Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an application that models a zoo that contains Lions and Ducks. Both Lion and Ducks are concrete classes that extend the abstract class Animal.

Write an application that models a zoo that contains Lions and Ducks. Both Lion and Ducks 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.235235 kg duck

0.233535 kg lion

Think out what variables, gettters, 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 specification:

- Contains a List of Animals

- public void addAnimal(Animal a) takes a reference to an Animal (an instance of one of the concrete subclassesof 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().

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.6234234 kg duck

animal 1 is a 1.2312512 kg duck

animal 2 is a 123.24242 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

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

Students also viewed these Databases questions

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

=+country competitive advantages? Why? Support your point of view.

Answered: 1 week ago

Question

=+from: a) a MNEs perspective? and b) the HRM managers perspective?

Answered: 1 week ago