Consider the game of Nim (a simplified version). There is a heap of X stones. tw
ID: 3667328 • Letter: C
Question
Consider the game of Nim (a simplified version). There is a heap of X stones. two players take turns to remove certain number of stones from the heap. In its turn, a player can choose to remove 1, 2, or 3 stones from the heap. Whoever removes the last stone loses the game. Write a java program Nim to simulate the game as follows: - At the beginning, use scanner to read the user input (a positive integer no larger than 10) as the number of stones to initialize the game. - In each turn, use scanner to read player 1’s input (1, 2, or 3), indicating how many stones player1 would like to remove from the heap. - Check if the last stone has been removed. If yes, print out who wins the game. Terminate program. - Then, let player 2 decide how many stones it would like to remove in the same way. - Check if the last stone has been removed. If yes, print out who wins the game. Terminate program. - Otherwise, repeat the stone removing process. What to program: The skeleton of the program is given to you in Nim.java. Finish the program by yourself.