Homework #4 Assignment

As a basis, use the sample code you were asked to download at the beginning of this week, at the start of the lecture on Interfaces.

Create a new abstract class - Pet - whose declaration states that the class implements the Animal and Comparable<Pet> interfaces. Within the Pet class create protected attributes for name and age. Implement public accessor methods for these attributes. Implement the public compareTo() method that compares Pets by their ages.

Modify the Dog, Cat, and Goldfish classes so that they extend the Pet class rather than implementing the Animal interface. Remove the name and age attributes from each class, since they will now be inherited from Pet.

In the main driver class, change the kennel declaration to be a collection of Pets rather than a collection of Animals. 

After adding the Pets to the collection as usual (where the Pets are added in age-random order), insert a Collections.sort(kennel) statement. Make sure that your implementation of the Comparable interface within the Pet class is working. After the call to Collections.sort(kennel), iterate through the sorted kennel and print each Pet; they should appear in age-ascending order.

Submit your .java files to the Week 4 Homework assignment in Blackboard.