Я получаю сообщение об ошибке, говоря, что я не реализую метод compareTo, когда я есть. Мой код выглядит следующим образом (я опустил методы доступа, так как они прекрасно):Цена не является абстрактом и не переопределяет абстрактный метод compareTo (java.lang.Object) в java.lang.Comparable
public class Rate implements Comparable
{
private int month;
private int day;
private int year;
private double rate;
private int a;
private int b;
private int c;
private int d;
// The constructor method for the class
public Rate(int month0, int day0, int year0, double rate0)
{
month = month0;
day = day0;
year = year0;
rate = rate0;
}
public int compareTo(Rate obj) // @param obj the Rate object that will be compared another Rate object.
{
a = (int)rate - (int)obj.getRate();
b = year - obj.getYear();
c = month - obj.getMonth();
d = day - obj.getDay();
if (a != 0)
return a; // @return a The difference between rates for the two objects
else if (b != 0)
return b; // @return b The difference between years for the two objects
else if (c != 0)
return c; // @return c The difference between month for the two objects
else if (d != 0)
return d; // @return d The difference between days for the two objects
else
return 0; // @return 0 if the two objects are totally equal.
}
}
Это всегда мелочи. Благодаря тонне он отлично работает сейчас! –
Проголосуйте за ответ и примите его, если я вам помогу. – duffymo