Question: Extend the Organism object hierarchy from Section 13.3 so that there is a new class Carnivore as described in Self-Test Exercise 13 on page 710.
Extend the Organism object hierarchy from Section 13.3 so that there is a new class Carnivore as described in Self-Test Exercise 13 on page 710. Use the hierarchy in a model of life on a small island that contains shrubs, geese that eat the shrubs, and foxes that eat the geese. The program should allow the user to vary the initial conditions on the island (such as the number of foxes, the amount of food needed to sustain a fox, and so on).
Data from Self-Test Exercise 13
Design and implement a new class extended from the Animal class. The new class, called Carnivore, has one new method with the heading shown here:
public void chase(Animal prey, double chance)
When chase(prey, chance) is activated for some carnivore, the carnivore chases the prey. The probability of actually catching the prey is given by the parameter chance (which should lie between 0 and 1—for example, 0.75 for a 75% chance). If the prey is actually caught, then this will also activate the carnivore’s eat method and (sadly) will activate the
prey’s expire method.

if (Math.random( ) < chance) { || Code for catching and eating the prey
Step by Step Solution
3.53 Rating (174 Votes )
There are 3 Steps involved in it
Heres an implementation of the Carnivore class based on the requirem... View full answer
Get step-by-step solutions from verified subject matter experts
