public class ComparableCat implements Animal, Comparable { private String animalName; public ComparableCat(String nameIn) { animalName = nameIn; } public String getName() { return animalName; } public void setName(String nameIn) { animalName = nameIn; } public String makeSound() { return "meow"; } public String toString() { return animalName; } /* public int compareTo(Object other) { //What is the risk of the following line of code? ComparableCat localCat = (ComparableCat)other; return this.getName().compareTo(localCat.getName()); } */ public int compareTo(Object other) { //What are the risks with this version? Animal localAnimal = (Animal)other; return this.getName().compareTo(localAnimal.getName()); } public boolean equals(Object other) { //A variation on the one shown Monday - better or worse? try { ComparableCat localCat = (ComparableCat)other; return this.getName().equals(localCat.getName()); } catch (Exception e) { return false; } } } //Copyright 2010-2012 : Evan Golub