Objective: Implement a set of classes for the Animal Kingdom that will demonstra
ID: 3680630 • Letter: O
Question
Objective:
Implement a set of classes for the Animal Kingdom that will demonstrate polymorphism.
1. An Animal interface will have the following method headers:
public String makeSound()
public String move()
public String getFood()
public String eatFood()
public void describe()
An Animal will also have the following static class variable:
private static String type
2. Implement at least the following two subinterfaces of Animal (remember: interfaces extend interfaces, classes implement interfaces):
Mammal, and one class that implements it
Reptile, and one class that implements it
3. In each of the non-interface subclasses:
Create a name member variable
Override all the generic methods from the higher-level classes. (Use print statements describing what would happen for that method applied to that particular animal).
For example, the makeSound method in a Dog class might print "Bark! Bark!", while the getFood method might print "begging at the dinner table."
Override describe to print out the name and type, then call the previous four methods
You will need a 1-variable constructor that has a String parameter for the name of the Animal being constructed.
4. In a TestAnimal class, declare several animal objects that refer to the various subclasses. Calling the describe method for each animal will show that each behaves in its own way, appropriate to that type of animal.
For example,
Dog dog = new Dog("Rover");
dog.describe();
would result in the following being printed:
Rover is a Dog.
Rover says "Bark! Bark!"
Rover walks on four legs.
Rover gets food by begging at the dinner table.
Rover eats food by chewing.
5. In the TestAnimal class, also define an array variable named family that consists of 3 instances of each of your subclasses (there will be one class instantiated twice), each with a different name, such as Fido, Rover, etc. Using a loop, call the describe method for each of the three animals.
Zip your source code (you will have 6 files in total) in a file titled 'AnimalKingdom.zip'.
Upload this zip file to dropbox Remember that your source code MUST have appropriate headers and MUST contain appropriate comments.
Explanation / Answer
Please find the required classes below :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.