Animal

Animal

Your assignment is to create a hierarchy of classes representing animals.

The root of the hierarchy should be a class named Animal (in file Animal.java), described in more detail below.

There must be at least two subclasses of Animal (you are welcome to have more than two). If you have no other ideas, you may name the subclasses Pet (Pet.java) and Marine Animal (MarineAnimal.java), but you are welcome to choose different groups of animals.

Each of your subclasses of Animal must in turn have at least one subclass (it may have more). Each of these sub-sub-classes of Animal must represent a specific animal, such as dog, cat, green turtle, octopus, and so on. In total, you must have at least six of these classes, representing six different kinds of animals. Choose suitable names for each of these animal classes — the TA may award less than full credit if your names are not suitable, so if you choose an unusual animal, make sure an appropriate comment clearly explains why your choice is suitable. It is also your choice which of these animals belongs to which subclass of Animal, but again your score may depend on the appropriateness of your choices and/or on how well your comments explain your choices.

Your Animal class must have at least:

  • An instance variable to represent the animal’s current weight. You can choose the units (grams, kilograms, ounces, pounds, etc.). Your code must have a comment saying which units this variable represents.
  • Another instance variable to represent the animal’s weight when fully grown. This variable should use the same units as the previous variable.
  • Another instance variable to represent the animal’s current size. Again, you must both choose and document suitable units.
  • Another instance variable to represent the animal’s size when fully grown. This variable should use the same units as the previous variable.
  • A constructor that takes as parameters the initial values of all four instance variables, and initializes them accordingly.
  • A method eat that eats a certain amount of food, and increases the animal’s weight by 1% of the amount of food (but without ever exceeding the animal’s fully-grown weight), and similarly increases the animal’s size by exactly 1%, again never exceeding the animal’s fully grow size.
  • Accessor methods for each of the animal’s weight and size.

For your immediate subclasses of Animal, you should choose which instance variables (if any) and methods they provide. The same is true for the individual animal classes. The only requirement is that each of these classes must have at least one new instance method not present in any of its super classes. Again, choose suitable methods. For example, a Pet usually has a name, and a Marine Animal may or may not breathe air.

As well as its own unique method, each animal or group of animals may override one or more methods from its superclass(es). This is up to you.

You must also create a Test Animals class with a main method that does all of the following:

  • Create at least two animal objects of each class of each specific animal. Since you are required to create at least six specific animal classes, the test program will have at least twelve animal objects. Animals should be created with a reasonable minimum size and weight.
  • Feed each of the animals at least until it is fully grown. Once the animal is fully grown both in weight and in size, print the animal’s name and how many feedings it took for it to grow to full size and weight.
  • Call at least once each of the methods specific to each of the animal classes.
  • Call at least once each of the methods specific to each of the classes representing groups of animals.

Note

Please attach the requested programs below as your assignment submission.

The code in your Test Animals class need not be all in the main method, and in fact you are encouraged to create and use multiple methods within this class.