CISP401 Employee.java, part of my payroll app.


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import java.util.*;
  2.  
  3. public abstract class Employee implements Comparable<Employee> {
  4.  
  5. // Data Objects (
  6. private EmployeeData emp;
  7. private static final double TAX_RATE = 0.15;
  8. // )
  9. // Constructors (
  10. public Employee() {
  11. emp = new EmployeeData();
  12. }
  13. public Employee(String f, String l) {
  14. emp = new EmployeeData(f, l);
  15. }
  16. public Employee(MyString f, MyString l) {
  17. emp = new EmployeeData(f, l);
  18. }
  19. public Employee(EmployeeData d) {
  20. emp = new EmployeeData(d);
  21. }
  22. public Employee(Employee e) {
  23. emp = new EmployeeData(e.emp);
  24. }
  25. // )
  26. // Accessors (
  27. public EmployeeData info() {
  28. return new EmployeeData(emp);
  29. }
  30. private EmployeeData get() { // private for use by compareTo
  31. return emp;
  32. }
  33. public int compareTo(Employee other) { // This is a overloaded method from the Comparable class for comparing two object (in my case Employee objects) in alphabetical order (which is the default behavior with compareTO when using strings).
  34. return (""+ emp.last + emp.first).compareTo(""+ other.get().last + other.get().first); // compareTo with String inputs automatically puts them in alphabetical order.
  35. }
  36. // )
  37. // Mutators (
  38. public abstract Number grossPay();
  39. public Number taxAmount() {
  40. return grossPay() .times (TAX_RATE);
  41. }
  42. public Number netPay() {
  43. return grossPay() .minus (taxAmount());
  44. }
  45. public MyString formattedName() {
  46. return new MyString("" + emp.last + ", " + emp.first);
  47. }
  48. public String toString() {
  49. return emp.toString();
  50. }
  51. // )
  52. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.