Question: Captain Codejack and the Treasure Box ( Hint: this problem can be solved using recursion ) JAVA This question involves a game with gold coins
Captain Codejack and the Treasure Box Hint: this problem can be solved using recursion JAVA
This question involves a game with gold coins from Captain Codejacks treasure box. The game starts when the captain gives you some gold coins. He also sets a target number of coins and allows you to get a fixed number of extra coins at any step. In each step of the game, you can either request additional coins each time same amount of extra coins will be provided or if you have even number of gold coins in hand you can return half of your coins back to him. However, Captain Codejack allows you to have only a maximum number of steps in this game. You win the game when you end up with exactly the target number of gold coins in hand without exhausting your steps. If you lose the game, then Captain Codejack makes you walk the plank!
For example, suppose Captain Codejack gives you gold coins and sets your target to be and allows you maximum steps. He also agrees to give you coins each time you request for additional coins. Then, you can make the following moves steps
Begin the game with gold coins.
Step : Ask for additional coins. You get more coins making coin total to be
Step : Ask for additional coins. You get more coins making your coin total to be Step : Return half of your coins to the Captain, leaving coins in your hand. Step : Return half of your coins to the Captain, leaving coins in your hand. Step : Return half of your coins to the Captain, leaving coins in your hand. You have won the game as you end up with exactly coins, which was your target, in hand.
Write a Java program to solve the above problem. The solution indicates whether a win is possible.
boolean treasuregameint startcoins, int targetcoins, int extracoins, int maxsteps
Postcondition: A true return value means that it is possible to win the game.
A false return value means that it is not possible to win the coin game within the specified number of steps.
Programming Instructions:
Your program should allow the user to enter initial values arguments of the treasuregame
method These values are passed as commandline arguments in the order of the parameters.
The program should indicate whether it is possible or not possible to win the game.
Extra Credit: points: In case of winning possibility, display the movessteps that lead to winning the game.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
