Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help please this program is in java of all the requirem Overview of all the Requirements We want to write a program that will allow

help please this program is in java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
of all the requirem Overview of all the Requirements We want to write a program that will allow a human to play a little number game against the computer. The game is easy: we start with 21 available coins. Both the computer and the player then take turn taking between 1 to 3 coins (inclusive). The player who picks the last remaining coin wins. At the end, the program displays a message identifying who won: computer or human. Feature #1 - Bare Necessities (total 1 point] Write a Java program with an empty class and empty main method that compiles and runs successfully leven though it is really not doing anything at this point). [1 point] Feature #2 - Keep track of the winner & congratulate them (total 2 points] Keep track of who is winning with a whoWon integer variable, initialized to 0 (1 point) At the end of your program, display a different message depending on the value inside the variable [1 point); For value 1. display "The computer won, bow to your Al overlord" For value 2, display instead "The human player won, this time..." For any other value, display "Nobody won, something went wrong! To test, this feature, temporarily add a line of code assigning one of these values to the variable whoWon right before your IF-ELSE statements. Recompile and re-run the code, trying different values to make sure your program works in all relevant cases . Remember to remove this assignment once you are sure that your code is working properly and you are ready to start working on the next feature. Feature #3 - Adding our game loop (total 3 points] Feature #3 - Adding our game loop (total 3 points) Add a loop to your program that will keep iterating as long as the variable who Won is equal to 11 point Inside this loop, start by displaying the number of coins remaining (1 point). You will store that value inside a variable named coins that you will initialize to 21 before the loop [1 point) To test this feature simply set whoWon to one of the expected values (1 or 2) right before the end of the loop. That will allow you to ensure that the loop starts and stops after a single iteration. Remember to remove this assignment once you are sure that your code is working properly and you are ready to start working on the next feature Feature #4 - Computer playing alone (total 4 points) Add some code in your loop so that the computer plays the game alone. Start by generating a random integer number between 1 and 3 that you will store in an integer variable take that you will also have to declare and initialize (1 point). Reminder - The expression to obtain such a random value is: (int(Math.random() * 3)+1 Display a message stating "Computer takes N coins", where N will be replaced by the value of take [1 point). Deduct the value of take from the variable coins (1 point) and check whether coins is now 0 or less. If that is the case, assign 1 to the variable whoWon so as to indicate that the computer just took the last coin and therefore won (1 point) To test this feature, simply run the game and read its output on the console to ensure the number of available coins decreases correctly, based on the random number taken by the computer at each turn, and that the game actually ends when the computer takes the last coin. - Feature #5 - Dummy simulated human player joins the game [total 5 points) Feature #5 - Dummy simulated human player joins the game (total 5 points) At the beginning of your program, declare and initialize an integer variable wholsNext to 1 (1 point). That variable will indicate whose turn it is (computer or human player) Inside the game loop, check the contents of wholsNext . If it contains 1. set whols Next to 2 so that, during the next iteration, the human player will be able to play (1 point). Then, execute the code you added for feature #4 the computer is playing its turn) (1 point] If it contains 2, set wholsNext to 1 so that, during the next iteration, the computer will be able to play [1 point). Then, simulate for now) what a human player would do by simply decrementing coins by 1. You will remove this assignment statement once you start working on the next feature and are done testing this one. Next, check whether the value of coins is lesser or equal to Q. If it is, then assign 2 to the variable whoWon so as to indicate that human player just took the last con and therefore won (1 point). Feature #6 Real human player joins the game [total 3 points) Replace the simulated human player" code that simply decremented coins by 1 by code that, instead, prompt the user to enter a value between 1 and 3 (inclusive) (1 point).read an int value from the user [1 point), and store it in a new variable named youDecide that you will also have to declare and initialize to 0 at the beginning of your program (1 point). Last but not least, decrement the number of remaining coins by the value in youDecide [1 point] Please note that, for now, we are going to assume that the human player always provides a valid value, that is, an integer value between 1 and 3 (inclusive). your program (1 point. Last but not least, decrement the number of remaining coins by the value in youDecide [1 point) Please note that, for now, we are going to assume that the human player always provides a valid value, that is an integer value between 1 and 3 (inclusive) Feature #7 - Never trust users [total 5 points] Last but not least, we now want to make our program a bit more robust to human error if the user enters a value lesser than 1. we will display a message reminding them that they need to take at least 1 coin during each of their turn (1 point). If they enter a value greater than 3, we display a message reminding them that they cannot take more than 3 coins during each of their turn [1 point). However, we want to go further and make sure that the program keeps prompting the user to enter a number of coins until they provide a proper value between 1 and 3 (inclusive). To realize this last feature, introduce another loop, declare any variables you might need, and determine where your new code should be added in the program [3 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

5. Develop the succession planning review.

Answered: 1 week ago