// Zorah Fung, CSE 143 // A class representing a Cat object public class Cat implements Comparable { private String name; private int lives; private double weight; // Constructs a new cat with the given name, number of lives and weight public Cat(String name, int lives, double weight) { this.name = name; this.lives = lives; this.weight = weight; } // Returns < 0 if this cat comes before the other given cat // Returns > 0 if this cat comes after the other given cat // Returns 0 if this cat is the same as the other given cat // Orders cats by lives, then by weight then by name public int compareTo(Cat other) { if (this.lives != other.lives) { return this.lives - other.lives; } else if (this.weight < other.weight) { return -1; } else if (this.weight > other.weight) { return 1; } else { return this.name.compareTo(other.name); } } // Returns the String representation of this cat public String toString() { return "(^=.=^)" + name + " {" + lives + ", " + weight + "}"; } }