// A class representing a Cat object public class Cat implements Comparable { private String name; private int lives; private double cuteness; // Constructs a new cat with the given name, number of lives and cuteness public Cat(String name, int lives, double cuteness) { this.name = name; this.lives = lives; this.cuteness = cuteness; } // Returns the String representation of this cat public String toString() { return "(^=.=^)" + name + " {" + lives + ", " + cuteness + "}"; } // Returns a number < 0 if this Cat comes before other // Returns a number > 0 if this Cat comes after other // Returns 0 if this Cat and the other are the same // Cats are ordered first by lives, // then cuteness (with cuter cats coming first), then name (in alphabetical order) public int compareTo(Cat other) { if (this.lives != other.lives) { return this.lives - other.lives; // only works for ints } else if (this.cuteness != other.cuteness) { if (this.cuteness < other.cuteness) { return 1; } else { // cuteness > other.cuteness return -1; } } else { // lives and weight are equal return this.name.compareTo(other.name); } } }