Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/JavaCS2/src/comparables/Person.java /JavaCS2/src/comparables/Student.java /JavaCS2/src/comparables/Employee.java #2 Recall that the Person class implements the comparable interface public clase Person implements Comparable Now suppose that we want to compare
/JavaCS2/src/comparables/Person.java /JavaCS2/src/comparables/Student.java /JavaCS2/src/comparables/Employee.java
#2
Recall that the Person class implements the comparable interface public clase Person implements Comparable Now suppose that we want to compare employees by their salary. Since Employee extends Person, Employee already implements Comparable, via the Person compareTo method, which compares Person objects by age. Now we want to override that compareTo method in the Employee class in order to make the salary comparisons. For this assignment, modify the tmployee class by implementing a new compareTo method for that cass. Enter the appropriate code in the space provided below, so that employee A is considered less than employee B if the salary of employee A is less than the salary of employee B. Aso, if the salary of employee A is equal to that of employee B, then they should be equal. Remember that the code you enter is located in the Employee dass Compares this object with the specified object for order. @param o the Object to be compared. public int compareTo (Object obj)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started