Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Recall that the Person class implements the Comparable interface: public class P

ID: 3627559 • Letter: R

Question

Recall that the Person class implements the Comparable interface:

public class 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 Employee class by implementing a new compareTo method for that class. 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. Also, 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 class.

/**
* Compares this object with the specified object for order.
* @param o the Object to be compared.
*/
public int compareTo(Object obj)
{
//your code here!

my answer:
double b = ((Employee)obj).getSalary();
double a = this.salary;
return(a-b);

but I got an error that read:
possible loss of precision
found : double
required: int

Can someone please help????

Explanation / Answer

// now change and work out as below !!
my answer:
double b = ((Employee)obj).getSalary();
double a = this.salary;
return (int)(a-b);