CISC370-010 Project 2

Assigned: June 13, 2001, Due: June 20, 2001
Animal Hierarchy classes
This project counts for 10% of the overall grade

Objective

The objective of this assignment is to become familiar with using inheritance, exceptions and some more standard classes in Java.

The Assignment

In this project you will be making several classes used to describe animals. At the top of the hierarchy will be an Animal class. Below it are WildAnimal and Pet classes. Below WildAnimal you will have a WildRabbit class. Below the Pet class you will have PetRabbit, Dog and Cat classes. There will also be a TestDriver class with a main() method to test out the classes. These classes will be expanded on in future projects.

The Animal class

This class will require the most work for this project. The Animal class will have several protected data members (which other classes will inherit). These data members will describe animals as follows:
The species, name, color and diet members should be String objects. The gender data member should be a boolean where true will be used for female and false for male. The weight member should be a double, while dateOfBirth should be a Calendar object. And finally pictureURL, and descriptionURL should be URL objects.

Each of the data members should have an accessor (starting with get) and a mutator (starting with set) method (i.e. getSpecies() and setSpecies()). There will be a constructor, which takes each of the data members and initializes them. You also need to implement an age() method that returns the age of the animal in years as a double (this will require some research in how to use the Calendar class). And finally, you need to implement a toString() method to return the data nicely for people, to printout.

The other classes

The Pet and WildAnimal classes will extend the Animal class. Their contructors should call super to initialize the inherited data members. The Pet class adds two protected data members, housetrained (a boolean, true if housetrained, false if not) and disposition (a String to describe the dispostion of the Pet). The WildAnimal class just adds one protected data member, habitat, a String describing the animal's habitat. Each of these additional data members will need get and set methods. These classes also should implement toString(), which calls super.toString() to take care of inherited data and adds on the new data members.

The WildRabbit class extends WildAnimal and adds two protected data members:

The Cat class adds the following data members:

The Dog class adds the following data members:

The PetRabbit class just adds the breed data member.

Again these classes should use super in their constructor, have get and set methods for their added on data members, and implement toString(). Remember one of the main points of OOP is code reuse, try to avoid having duplicate code as much as possible (use super). Some example code to use for the PetRabbit class is given here.

The TestDriver class and main()

A sample TestDriver class is given here. You should add on to it to test out each of the classes that you wrote. Search the web for pictures and descriptions of animals to use for the URL members. These URLs will be used in future projects to display the picture and the description page in a GUI. For now just follow the example and test out each class as the example tests out PetRabbit. Note that you will need to use exception handling when using the URL class.

Example output

Here is sample output for the driver program given above:
Info on Glenda!
   Name:  Glenda
Species:  Rabbit
  color:  white
 Gender:  Female
 weight:  2.0
    DOB:  Feb 15, 1998 (age: 3.31)
   diet:  grass
PictURL:  http://plan9.bell-labs.com/plan9dist/img/plan9bunnywhite.jpg
DescURL:  http://plan9.bell-labs.com/plan9dist/glenda.html
houstrained:  true
disposition:  Extemely Friendly
breed:  Plan9 Bunny

Grading

All of the Animal classes (data members and methods working) - 50%
The TestDriver class and test run of your main() (test each class at least once) - 30%
javadoc documentation on your webpage - 20%

Turn In

All of your code and test run of each class in TestDriver stapled together with no blue print header sheets. (Note: 5 points will be deducted if not stapled neatly together) Include documentation on your webpage (with no source code).