Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago