Question: USE JAVA ONLY> AND PLEASE USE METHODS The game of Nim starts with a random number of stones between 15 and 30. Two players alternate

 USE JAVA ONLY> AND PLEASE USE METHODS The game of Nim

USE JAVA ONLY> AND PLEASE USE METHODS

The game of Nim starts with a random number of stones between 15 and 30. Two players alternate turns and on each turn may take either 1, 2, or 3 stones from the pile. The player forced to take the last stone loses. Create a Nim application that allows the user to play against the computer. In this version of the game, the application generates the number of stones to begin with, the number of stones the computer takes, and the user goes first. The Nim application code should: prevent the user and the computer from taking an illegal number of stones. For example, neither should be allowed to take three stones when there are only 1 or 2 left. include an isValid Entry() method to check user input. include a drawStones() method that generates a random number from 1 to 3 for the number of stones the computer draws. include separate methods to handle the user's turn and the computer's turn. Application output should look similar to that shown on the next page: There are 22 stones. How many would you like? 3 There are 19 stones. The computer takes 2 stones. There are 17 stones. How many would you like? 3 There are 14 stones. The computer takes 2 stones. There are 12 stones. How many would you like? 3 There are 9 stones. The computer takes 3 stones. There are 6 stones. How many would you like? 3 There are 3 stones. The computer takes 3 stones. The player beats the computer! The game of Nim starts with a random number of stones between 15 and 30. Two players alternate turns and on each turn may take either 1, 2, or 3 stones from the pile. The player forced to take the last stone loses. Create a Nim application that allows the user to play against the computer. In this version of the game, the application generates the number of stones to begin with, the number of stones the computer takes, and the user goes first. The Nim application code should: prevent the user and the computer from taking an illegal number of stones. For example, neither should be allowed to take three stones when there are only 1 or 2 left. include an isValid Entry() method to check user input. include a drawStones() method that generates a random number from 1 to 3 for the number of stones the computer draws. include separate methods to handle the user's turn and the computer's turn. Application output should look similar to that shown on the next page: There are 22 stones. How many would you like? 3 There are 19 stones. The computer takes 2 stones. There are 17 stones. How many would you like? 3 There are 14 stones. The computer takes 2 stones. There are 12 stones. How many would you like? 3 There are 9 stones. The computer takes 3 stones. There are 6 stones. How many would you like? 3 There are 3 stones. The computer takes 3 stones. The player beats the computer

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!