Create animal objects of each class of each specific animal


Homework

Your homework 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 MarineAnimal (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:

1. 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.

2. Another instance variable to represent the animal's weight when fully grown. This variable should use the same units as the previous variable.

3. Another instance variable to represent the animal's current size. Again, you must both choose and document suitable units.

4. Another instance variable to represent the animal's size when fully grown. This variable should use the same units as the previous variable.

5. A constructor that takes as parameters the initial values of all four instance variables, and initializes them accordingly.

6. 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.

7. 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 superclasses. Again, choose suitable methods. For example, a Pet usually has a name, and a MarineAnimal 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 TestAnimals class with a main method that does all of the following:

1. 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.

2. 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.

3. Call at least once each of the methods specific to each of the animal classes.

4. Call at least once each of the methods specific to each of the classes representing groups of animals.

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

Format your homework according to the give formatting requirements:

1. The answer must be double spaced, typed, using Times New Roman font (size 12), with one-inch margins on all sides.

2. The response also includes a cover page containing the title of the homework, the course title, the student's name, and the date. The cover page is not included in the required page length.

3. Also include a reference page. The references and Citations should follow APA format. The reference page is not included in the required page length.

Solution Preview :

Prepared by a verified Expert
Programming Languages: Create animal objects of each class of each specific animal
Reference No:- TGS03183553

Now Priced at $30 (50% Discount)

Recommended (91%)

Rated (4.3/5)