public class ExampleOfWritingAClass { public static void main(String[] args) { Dolphin dolph1 = new Dolphin(10, "Flipper"); dolph1.setIQ(200); System.out.println(dolph1); } } // public class class Dolphin implements Comparable { private int myIQ; private String myName; public Dolphin() { myIQ = 0; myName = ""; } public Dolphin(int iq, String name) { myIQ = iq; myName = name; } public int getIQ() { return myIQ; } public void setIQ(int iq) { myIQ = iq; } public String toString() { return "IQ = " + myIQ + " name = " + myName; } public int compareTo(Object other) { if (myIQ > ((Dolphin) other).myIQ) { return 1; } else if (myIQ < ((Dolphin) other).myIQ) { return -1; } else { if (myName.compareTo(((Dolphin) other).myName) > 0) { return -1; } else if (myName.compareTo(((Dolphin) other).myName) < 0) { return 1; } } return 0; // equal IQ's and equal names } }// end of Dolphin class