Question: Write an application in java that models a zoo that contains Lions and Ducks. Both Lion and Duck are concrete classes that extend the abstract
Write an application in java that models a zoo that contains Lions and Ducks. Both Lion and Duck are concrete classes that extend the abstract class Animal. You must be able to call the following methods on any Animal:
public double getWeight() works the same for all Animals
public String call() prints out a different String for each type of Animal
-Lion's call() method prints "roar" and Duck's prints "quack"
public String attack() prints a different String for each type of animal
-Lion's attack() prints the String "bares teeth and bites" and Duck's prints "pecks with its ferocious bill"
public String toString() returns Strings like these:
0.6830105287458925 kg duck
135.9492664745286 kg lion
Think out what variables, getters, setters, and constructors your classes will need. All ducks have the same call, and all Lions have the same call, but different animals of each class have different weights.
Write the class Zoo so that it meets these specifications:
Contains a List of Animals
public void addAnimal(Animal a) takes a reference to an Animal (an instance of one of the concrete subclasses of Animal) and adds it to the list.
public void listAnimals() prints the message "the zoo contains the following animals:" and then prints each animal's list index and toString() String.
public void makeNoise() runs the call() method for each animal in the list.
public void jailBreak() runs the attack() method for each animal in the list.
The class ZooDriver should hard code some animals, call listAnimals(), call makeNoise(), and then call jailBreak(). You do not need to take user input for this problem. Here is sample output from my ZooDriver for a zoo with only 3 animals:
The zoo contains the following animals:
animal 0 is a 0.6177069624304481 kg duck
animal 1 is a 1.137326599134231 kg duck
animal 2 is a 144.04307883470435 kg lion
animal 0 quacks
animal 1 quacks
animal 2 roars
animal 0 pecks with its ferocious bill
animal 1 pecks with its ferocious bill
animal 2 bares teeth and bites
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
