//USER DEFINED CLASS WITH SPECIFIED ORDERING //Konstantin Voevodski //CS112A1 Spring 2008 //a user defined class which implements the Comparable interface //the sort implementations given in the textbook will work //with an array of Monkey objects public class Monkey implements Comparable { private String name; private int age; private String color; public Monkey(String name, int age, String color) { this.name = name; this.age = age; this.color = color; } public String toString() //return a String representation of this Monkey //print and println call the toString method of the Object { return(name + ", a " + color + " monkey of age " + age); } public int getAge() { return age; } public int compareTo(Monkey m) //a monkey with the smaller age is considered smaller //output is negative if this monkey is smaller than m //positive if this monkey is greater than m, and 0 otherwise, //as required by specification { return(this.age - m.getAge()); } }