trouble comparing objects of another class
どうすればいいですか?
私はおいしい例を作りました。うまくいけば、コードは一目瞭然です。
Cake.java:
public class Cake implements Comparable<Cake> {
private final int tastyness;
public Cake(tastyness) {
this.tastyness = tastyness;
}
public int compareTo(Cake other) {
return this.tastyness - other.tastyness;
}
}
makeBestDinner.java:
public class makeBestDinner {
List<Cake> cakes = new ArrayList<cake>();
// Make a whole lot of cakes here
if (cakes[0] > cakes[1]) {
System.out.println("The first cake tastes better than the second");
}
// Do the same for beverages
}