Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Greenfoot I am making FruitWorld Create an Actor subclass named Fruit using the

ID: 3840520 • Letter: G

Question

Greenfoot

I am making FruitWorld

Create an Actor subclass named Fruit using the "apple.png" image. Include the following class members:

A private numeric variable to store a score value.

A public constructor with a single numerical parameter that sets the score from the previous step.

A public act() method with code to move the fruit downward by one pixel each scenario cycle. In addition, add code to stop the scenario (game over!) if any fruit reaches the bottom of the window.

---Create a Fruit subclass named Banana using the "banana.png" image. Add a constructor to the Banana class that has a score parameter and calls the constructor of its superclass. Remove the act() method.

---Create a Fruit subclass named Cherry using the "cherry.png" image. Add a constructor to the Cherry class that has a scoreparameter and calls the constructor of its superclass. Remove the act() method.

--Add an act() method to FruitWorld. In the act() method, add one of the three fruits with a random chance of 3% when the act() method is called. Choose which fruit (Fruit, Banana, Cherry) randomly and assign each fruit a different score value. Add the chosen fruit at random x-coordinates at the top of the world, where y is zero. At this time you should be able to see fruit fall downward in your scenario until one of them reaches the bottom of the screen.

--In FruitWorld, add a private instance variable named score suitable for storing integers. Initialize the score variable to 0.

-- Also in FruitWorld add a public method named addToScore() to the world subclass with the following signature:

public void addToScore(int amount)

When called, the addToScore() method adds the amount parameter to the score variable. Then the method displays the word "Score: " followed by the current value of the score variable by calling showText(). Display the score message in the upper left-hand corner of the scenario's display.

Call the addToScore() from the FruitWorld constructor so that an initial score of 0 is displayed when the scenario is first compiled.

Explanation / Answer

program: