Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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

1 answer below »
We’re gonna make a race between animals. The animals are lion, panther, hippo, cat, dog
and ra
it. 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 Ra
it
Speed 3.5 – XXXXXXXXXX – XXXXXXXXXX – XXXXXXXXXX – XXXXXXXXXX – XXXXXXXXXX – 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
andomized 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 Ra
it
4.16 eat XXXXXXXXXX.92
eat XXXXXXXXXX43 5.94
XXXXXXXXXXeat XXXXXXXXXX
… … … … … …
XXXXXXXXXX XXXXXXXXXX20
XXXXXXXXXX XXXXXXXXXX08
XXXXXXXXXX XXXXXXXXXX.10
The competition was won by the Panthe
a) Make a class with class inheritance to represent the animals, so that you can use
polymorphism.
) 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)
Answered Same Day Dec 19, 2021

Solution

Aditi answered on Dec 19 2021
148 Votes
Solution/Animal.java
Solution/Animal.java
import java.util.Random;
public class Animal {
    
    private String name;
    private double minSpeed;
    private double maxSpeed;
    private int probabiltyToEat;
    private double distanceCovered;
    public Animal(String name, double minSpeed, double maxSpeed, int probabiltyToEat) {
        this.name = name;
        this.minSpeed = minSpeed;
        this.maxSpeed = maxSpeed;
        this.probabiltyToEat = probabiltyToEat;
        this.distanceCovered = 0;
    }
    public String getName() {
        return name;
    }
    
    public double getCu
entSpeed(){
        Random random = new Random();
        double speed = minSpeed + (maxSpeed - minSpeed) * random.nextDouble();
        return speed;
    }
    public double getMaxSpeed() {
        return maxSpeed;
    }
    public double getMinSpeed() {
        return minSpeed;
    }
    public int getProbabiltyToEat() {
        return probabiltyToEat;
    } 
    public d...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here