Question: Please develop a Java program for the game of Nim. This version of the Nim game consists of a pile of stones, ranging from 10

Please develop a Java program for the game of Nim. This version of the Nim game consists of a pile of stones, ranging from 10 to 16. The player and the computer will alternate (take turn) to remove 1, 2, or 3 stones from the pile. The player will go first. The one, who takes the last stone, loses. The number of stones in the pile will be randomly generated at the beginning of the game and be displayed. At the end of a game, the player will be prompted to either start another game or to quit. This program will keep track of the total number of games played and the total number of games the player has won. The number of stones removed by the computer will be randomly decided. This program will perform the necessary error checking: the number of stones to remove cannot be greater than 3 or the number of stones left in the pile.

I use JGRASP so it must all be in one class.

Sample output: (underline denotes a user input)

Welcome to Nim game!

Game #1. There are 10 stones in the pile. You may remove 1, 2, or 3 stones at a time.

How many stones would you like to remove? 3

I removed 3 from the pile. There are 4 stone(s) in the pile.

How many stones would you like to remove? 3

I remove 1 from the pile. There are 0 stone(s) in the pile.

Congratulations! You win You have played 1 game(s). You have won 1 game(s). Would you like to play again? (Y/N): N

Have a lucky day.

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!