For this project, you will write a hierarchy of parent classes, child classes, and interfaces, as described below.
Write classes or interfaces to represent the following:
1. All animals have a name.
2. All animals have a method "isWarmBlooded" that returns a boolean.
3. All classes have a toString method that returns: the animal's name, whether the animal is warm blooded, and a list of all animal names that apply to the animal.
4. Animals that can be adopted as pets have a method "homeCareDirections" that returns a text description of how to care for the animal.
5. Animals that live in water (are water dwellers) have a method "canLiveOutOfWater" that returns a boolean of whether the animal also can live out of the water (on land).
6. Animals that have wings have a method "canFly" that returns a boolean of whether the animal can fly.
You need to decide on the structure of the classes/interfaces. Consider:
This part of the assignment isn't necessarily difficult from a programming perspective. What you should spend time on is carefully considering the design of you classes and how they should be related through inheritance or interfaces. To get full credit:
Write an equals method in the Animal class. Two animals are logically equivalent if they have the same name (ignoring capitalization) and the same warm blooded status.
Note: you do not have to override the equals method in any other class.
I've provided a driver program that creates some objects. The program will print various categories of animals. You will fill in the code to accomplish this. For full credit, you must use polymoprhism in this code.
AnimalKingdomDriver.java
import java.util.*;
public class AnimalKingdomDriver {
public static void main(String[] args) {
ArrayList< Animal > animalList = new ArrayList< >();
Bat bat = new Bat("Count Batula");
animalList.add(bat);
animalList.add(new BlueWhale("Blubby Blubs"));
animalList.add(new Cat("Ms. Purrfect"));
animalList.add(new Emu("Outback Ollie"));
animalList.add(new Goldfish("Sammy Swimmer"));
animalList.add(new Otter("Henry Handholder"));
animalList.add(new Parakeet("Songbird Stu"));
animalList.add(new Turtle("Shelly Silversteen"));
System.out.println("***** Here are all the animals. (8 animals printed)");
for (Animal animal : animalList) {
System.out.println(animal);
}
System.out.println("\n\n***** Check on the equals method.");
Bat batTest = new Bat("Count Batula");
System.out.println("Should print true: " + bat.equals(batTest));
batTest = new Bat("COUNT BATULA");
System.out.println("Should print true: " + bat.equals(batTest));
batTest = new Bat("Batman");
System.out.println("Should print false: " + bat.equals(batTest));
System.out.println("\n\n***** Here are just the mammals. (4 animals printed)");
for (Animal animal : animalList) {
if (animal instanceof Mammal) {
System.out.println(animal);
}
}
System.out.println("\n\n***** Here are the winged animals along with information about whether they can fly. (3 animals printed)");
for (Animal animal : animalList) {
if (animal instanceof Winged) {
Winged winged = (Winged) animal;
System.out.println(winged + "\t" + (winged.canFly() ? "Can fly" : "Cannot fly"));
}
}
System.out.println("\n\n***** Here are the adoptable animals along with their care directions. (4 animals printed)");
for (Animal animal : animalList) {
if (animal instanceof Adoptable) {
Adoptable adoptable = (Adoptable) animal;
System.out.println(adoptable + "\t" + adoptable.homeCareDirections());
}
}
System.out.println("\n\n***** Here are the animals that can dwell in water, along with whether they can also live on land. (4 animals printed)");
for (Animal animal : animalList) {
if (animal instanceof WaterDweller) {
WaterDweller waterDweller = (WaterDweller) animal;
System.out.println(waterDweller + "\t" + (waterDweller.canLiveOutOfWater() ? "Can also live on land" : "Cannot also live on land"));
}
}
}
}