Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In javaYou work in a zoo housing a wide range of animals. Among other classes, your zoo holds a Dragon named Smaug, a Spider named

In javaYou work in a zoo housing a wide range of animals. Among other classes, your zoo holds a Dragon named Smaug, a Spider named Charlotte, a Horse named ThePiebald, and two Sheep named Dolly and Dolly (a little clone humor here).
Your mission is to create five user-defined data types. They are the abstract super class Animal and the sub classes Sheep, Dragon, Spider, and Horse.
The Animal class will have a constructor and the following class members. Methods
abstract String eats(); // will return a String with the food the animal eats
abstract String whatType(); // will return a String with the type of animal it is
toString(); // will show the member instance values of the object
You will override the three methods above in each subclass and you will invoke the superclass default constructor in each subclass constructor via super(). Please use the @Override annotation where appropriate.
Instance Variables.
String name
int age
The Animal class will also have appropriate accessor and mutator methods for these two variables.
int static animalCount
The Animal class will have an appropriate accessor method for this variable. This variable will increment by one (using the Animal constructor) every time an object that is a subclass of Animal is instantiated.
Appropriate access modifiers will be assigned to all class members.
You will clone one sheep. That is, you will create an additional constructor in the Sheep class that will take all the information from the first sheep and use this information to instantiate a second sheep, making a deep copy of a Sheep object.
You will write an application (Zoo.java) that will create an object of each of the zoos four animals (and a sheep clone). Within the application you will create an array of type Animal and place each of the animals in the array. Then using a for loop and the Animals static variable animalCount, output to the screen each animals name, type, age, and diet using the overridden toString() method within each subclass.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions