For this project, you will write a hierarchy of parent classes, child classes, and interfaces, as described below.

Part 1 Animal Hierarchy

Write classes or interfaces to represent the following:

  • Adoptable
  • Animal
  • Bat
  • Bird
  • BlueWhale
  • Cat
  • Emu
  • Fish
  • Goldfish
  • Mammal
  • Otter
  • Parakeet
  • Reptile
  • Turtle
  • WaterDweller
  • Whale
  • Winged

Details/Requirements

1. All animals have a name.

2. All animals have a method "isWarmBlooded" that returns a boolean.

  • The method can be in the class directly or inherited.

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.

  • For an example, review the provided sample output.
  • The toString method can be in the class directly or inherited.

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.

Design Decisions

You need to decide on the structure of the classes/interfaces. Consider:

  • Which should be an abstract class? a concrete class?
  • Which should be an interface?
  • How should the classes be related through inheritance?
  • In what classes should methods be placed?
  • What methods should be overridden?
  • What information should be taken in as a parameter and what information can be hard-coded into a class?

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:

  • Your class hierarchy should make sense.
    • You can assume common knowledge or "googleable" facts about animals.
    • If you aren't sure how to describe a certain kind of animal, post to the discussion board!
    • You can also review my driver program output to see how I describe animals.
  • Place common code as high up in the hierarchy as possible.
  • Reduce duplicated/repeated code.
  • Declare classes that should not be instantiated as abstract.
  • In abstract classes, methods that must be implemented by all subclasses should be declared abstract.
  • Follow general principles of object oriented programming and good code design.
  • Use Java naming conventions accurately.
  • Remember that classes can only have one parent but can implement multiple interfaces.

Part 2 equals Method

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.

Part 3 Driver Program

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"));
}
}

}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.