Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions