Question: Captain Fictitious and Treasure Box (Hint: this problem can be solved using recursion) java porgram This question involves a game with gold coins from Captain
Captain Fictitious and Treasure Box (Hint: this problem can be solved using recursion) java porgram This question involves a game with gold coins from Captain Fictitious 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 Fictitious allows you to have only a maximum number of steps in this game. You win the game if you end up with exactly the target number of gold coins in hand without exhausting your steps. For example, suppose that Captain Fictitious gives you 60 gold coins and sets your target to be 18, and allows you maximum 6 steps. He also agrees to give you 42 coins each time you request for additional coins. Then, you can make the following moves (steps). Begin the game with 60 gold coins. Step 1: Ask for additional coins. You get 42 more coins making coin total to be 102. Step 2: Ask for additional coins. You get 42 more coins making your coin total to be 144. Step 3: Return half of your coins (144/2 = 72) to the Captain, leaving 72 coins in your hand. Step 4: Return half of your coins (72/2 = 36) to the Captain, leaving 36 coins in your hand. Step 5: Return half of your coins (36/2 = 18) to the Captain, leaving 18 coins in your hand. You have won the game as you end up with exactly 18 coins, which was your target, in hand. Write a Java program to solve the above problem. boolean treasure_game(int 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: 1. Your program should allow the user to enter initial 4 values (arguments of the treasure_game() method). Use appropriate message to indicate the user to enter the values. 2. The program should indicate whether it is possible or, not possible to win the game. [Extra Credit: 5 points]: In case of winning possibility, display the steps to follow to win the game.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
