Extend the Organism object hierarchy from Section 13.3 so that there is a new class Carnivore as

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. 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

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: