Question: integer.compareTo method Java . How do I make this method work? The instructions are as follows: compareTo(Employee otherEmployee) Implemented from the interface Comparable Specifically, Comparable

integer.compareTo method Java . How do I make this method work?

The instructions are as follows:

compareTo(Employee otherEmployee)

Implemented from the interface Comparable

Specifically, Comparable should be used for the interface. The method returns the following:

-1 is the current employee objects valuePoints is less than otherEmployees valuePoints

0 if the employees have equal valuePoints

1 if the current employee objects valuePoints is greater than otherEmployees valuePoints

The degree point values toward the valuePoints calculation (valuePoints = experience * degreeValue): None is worth 1 Associate is worth 2 Bachelors is worth 3 Masters is worth 4 Doctorate is worth 5

My code for this section:

public int compareTo(Employee otherEmployee) { return ((this.experience * (this.degree.ordinal() + 1)) == (otherEmployee.experience * (otherEmployee.degree.ordinal() + 1))); }

This throws an error:

Employee.java:133: error: incompatible types: boolean cannot be converted to int

What is wrong with my method? I tried swapping out == to - + and when I do, it won't have the correct output (-1, 0, or 1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!