/* * Kyle Pierce * Cse 143 * * Class Dog represents a dog */ public class Dog implements Comparable { private String name; private int age; private double weight; /* * Constructs a dog with the given name, age, and weight */ public Dog(String name, int age, double weight) { this.name = name; this.age = age * 7; this.weight = weight; } /* * Returns a String representation of this dog */ public String toString() { return "\n" + " / \\__\n" + " ( @\\___ name = " + name + "\n" + " / O age = " + age + " (dog years)\n" + " / (_____/ weight = " + weight + " lbs \n" + "/_____/ U" + "\n"; } /* * Compares this dog to the given other dog * Dogs are ordered first by age, then by weight, and finally by name */ public int compareTo(Dog other) { if (age != other.age) { return age - other.age; } else if (weight != other.weight) { if (weight < other.weight) { return -1; } else { return 1; } } else { return name.compareTo(other.name); } } }