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


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


Self-Test Exercise 13 Section 13.3


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:





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.


Note: You can use the Math.random method to determine whether the animal is caught, as shown here:








Dec 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here