We’re gonna make a race between animals. The animals are lion, panther, hippo, cat, dog and rabbit. The race is done through iterations and every animal runs at a randomized speed in every new...

We’re gonna make a race between animals. The animals are lion, panther, hippo, cat, dog and rabbit. The race is done through iterations and every animal runs at a randomized speed in every new iteration. The speeds are given in units of measurement per iteration. Every animal also has a probability to stop and eat along the way. When the animal eats, it’s not moving. These are the speeds and probability to eat for the animals:   Lion  Panther Hippo  Cat Dog  Rabbit Speed 3.5 – 4.5  3.7 – 5.3  3.3 – 3.7  3.3 – 3.9  3.5 – 4.1  0.2 – 6.6 Probability to eat 13%  23%  2%  3%  9%  2%

For example, the lion can have any speed between 3.5 and 4.5. And the animal gets a new randomized speed every iterations from its speed interval.


The first animal to move 1000 units of measurement has won. When the race has a winner, that animal will be printed out. If the panther won, the print will be “The competition was won by the Panther”. If for example both the panther and the Lion came over 1000 units of measurement at the same time, the print will be “The competition was won by the Panther and the Lion”.


Example:


Lion  Panther Hippo  Cat Dog  Rabbit 4.16  eat  3.65  3.34 3.16  0.92 eat  4.91 7.06 7.19  7.43 5.94 8.63 10.02 eat 10.79 11.09 11.69 … … … … … … 987.01 994.16 973.57 991.54 956.96 914.20 990.83 998.42 977.16 995.34 960.92 920.08 994.48 1003.30 980.85 999.03 964.76 926.10 The competition was won by the Panther


Make a class with class inheritance to represent the animals, so that you can use polymorphism. b) Make a class that contains the racing rules, where you create the different animals, starts the race and knows when it has ended. c) Implement the race as follow. The race is made through iterations. In every iteration the animal either runs forward, or stops to eat. (the animal doesn’t move while eating). Every animal has specific speeds and probability for stopping to eat. (Check the chart above). The animals speeds change in every iteration. (Notice that you need to use polymorphism here to get max points!) d) Implement the print for the winner. Notice that more than one animal can win. If that’s the case, all winning animals will be printed. (The method public String toString() can be helpful for the print)

May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here