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:
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 hereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started