/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.util.*; public abstract class Employee implements Comparable<Employee> { // Data Objects ( private EmployeeData emp; private static final double TAX_RATE = 0.15; // ) // Constructors ( public Employee() { emp = new EmployeeData(); } emp = new EmployeeData(f, l); } public Employee(MyString f, MyString l) { emp = new EmployeeData(f, l); } public Employee(EmployeeData d) { emp = new EmployeeData(d); } public Employee(Employee e) { emp = new EmployeeData(e.emp); } // ) // Accessors ( public EmployeeData info() { return new EmployeeData(emp); } private EmployeeData get() { // private for use by compareTo return emp; } 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). return (""+ emp.last + emp.first).compareTo(""+ other.get().last + other.get().first); // compareTo with String inputs automatically puts them in alphabetical order. } // ) // Mutators ( return grossPay() .times (TAX_RATE); } return grossPay() .minus (taxAmount()); } public MyString formattedName() { return new MyString("" + emp.last + ", " + emp.first); } return emp.toString(); } // ) }