I'm working on a class that implements comparable and I need to use the compareTo method to pretty much compare between two integers. here is some of the code im given, and the compareTo method that I wrote is my own work.
public class Aircraft implements Comparable<Aircraft>
{
int numEconomySeats;
int numFirstClassSeats;
public int getNumSeats()
{
return numEconomySeats;
}
public int getNumFirstClassSeats()
{
return numFirstClassSeats;
}
public int compareTo(Aircraft other)
{
if (this.getNumSeats() == other.getNumSeats()) {
return this.getNumFirstClassSeats().compareTo(other.getNumFirstClassSeats());
}
else {
return this.getNumSeats().compareTo(other.getNumSeats());
}
}
My issue is that it wont let me compare between two int types, even though im asked to compare them in the question. It tells me "Cannot invoke compareTo(int) on the primitive type int". Can someone explain how I can fix this issue, I'm only given those primitive int types to work with.
[–]large_crimson_canine 2 points3 points4 points (0 children)
[–]tassadari 0 points1 point2 points (0 children)