Question: Candy Mountain: This question is about a game involving candy. There is a place called Candy Mountain, which initially has a randomly chosen amount of

Candy Mountain: This question is about a game involving candy. There is a place called Candy Mountain, which initially has a randomly chosen amount of candies in the range 0 to 99 inclusive that are not owned by any player. When a player gives some candies to the Candy Mountain, the player gets back twice that number of candies from the Candy Mountain. However, if the amount owed to the player is more than what the Candy Mountain has to give, the player will not get any candies. (To go beyond is as wrong as to fall short.) Define a class CandyPlayer with:

Candy Mountain: This question is about a game involving candy. There isa place called Candy Mountain, which initially has a randomly chosen amount

a method called play that takes the number of candies to give to the Candy mountain (int) and returns true if and only if the input number is less than or equal to the number of candies that this CandyPlayer has. Update the number of candies that each of this CandyPlayer and the Candy mountain has. Refer the following example. Example: CandyPlayer.getMountainCandy(); // Suppose this returns 50 CandyPlayer player = new CandyPlayer(80); player.play(100); // this returns false player.play (20); // this returns true CandyPlayer.getMountainCandy(); // this returns 30 player.getMyCandy ( ) ; // this returns 100 since the player gave 20 to the Candy mountain and got 40 from the mountain player.play (50); // this returns true CandyPlayer.getMountainCandy (); // this returns 80 because 100 > 80 player.getMyCandy ( ) ; // this returns 50 import java.util.Random; public class CandyPlayer { private static int totalCandy = (new Random ( ) ) .nextInt(100); private static int num candyMountain; private int num_candyPlayer; public CandyPlayer(int num_candyPlayer) { this.num_candyPlayer = num_candyPlayer; // Getter public int getMyCandy () { return num_candyPlayer; // Static Getter public static int getMountainCandy ( ) { return num_candyMountain; public boolean play(int num) { // Insert code here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!