// Erika Wolfe, 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 the String representation of this cat public String toString() { return "(^=.=^)" + name + " {" + lives + ", " + weight + "}"; } // 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 weight, then name public int compareTo(Cat other) { if (lives != other.lives) { return lives - other.lives; // only works for ints } else if (weight != other.weight) { if (weight < other.weight) { return -1; } else { // weight > other.weight return 1; } } else { // lives and weight are equal return name.compareTo(other.name); } } }