This activity explores the use of the Comparable interface.
In addition to the Solution document, the project for this activity contains two classes:
The class Employee contains personnel details about employees. It has a constructor and a number of public getter/setter methods. These features of the class have already been implemented for you.
The class is also required to implement the Comparable<Employee> interface, which means that it must provide a compareTo method with the following header:
public int compareTo(Employee emp)
1. Open the source file for class Employee. Modify the class so that it implements the Comparable interface for the correct type, and write an appropriate compareTo method, so that employees can be ranked in order of salary.
Now run the project and check the output.
2. Now implement the compareTo method so that employees are sorted by their names instead of by their salaries.