Introduction to the Comparable Interface, Part II

In the previous introduction to interfaces assignment, you made this code work:

Given the following code:

public static void main(String[] args) {
    Cow[] cows = { new Cow(2000, "Hulk"),
                   new Cow(),
                   new Cow(1600, "Bessie"),
                   new Cow(1700, "Moohead"),
                   new Cow(),
                   new Cow(1900, "Big Time Jones") };

    printArray(cows);
    Arrays.sort(cows);
    printArray(cows);
}

with output:

Hulk, Anonymous Cow, Bessie, Moohead, Anonymous Cow, Big Time Jones, 
Bessie, Moohead, Anonymous Cow, Anonymous Cow, Big Time Jones, Hulk, 

 

Now make this code work:

public static void main(String[] args) {
    Animal[] animals = { new Horse(2000, "Hulk"),
                         new Wombat(),
                         new Wombat(1600, "Bessie"),
                         new Cow(1700, "Moohead"),
                         new Wombat(),
                         new Wildebeest(1900, "Big Time Jones") };

    
    printArray(animals);
    for (Animal a : animals) {
        a.eat(200);
    }
    Arrays.sort(animals);
    printArray(animals);
}

with the this output:

Hulk:2000, Anonymous Wombat:1800, Bessie:1600, Moohead:1700, Anonymous Wombat:1800, Big Time Jones:1900, 
Wombats don't gain weight when they eat!
Wombats don't gain weight when they eat!
Wombats don't gain weight when they eat!
Bessie:1600, Anonymous Wombat:1800, Anonymous Wombat:1800, Moohead:1900, Big Time Jones:2100, Hulk:2200,