Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a chips game that satisfy the folowing condition using jave language. 1- T

ID: 3648004 • Letter: W

Question

Write a chips game that satisfy the folowing condition using jave language.

1- There are two player and 50 chips total.
2- The players should switch turns until one of them wins.
3- The first move must be between 1 and 48
4- Every other move must be between 1 and (2*last move) but not more than remaining total.
5- player who takes the last chip loses.

The outline of the java code:

int player = 1;
// get first move
// establish 1) the max to take on next move 2) numChips 3) next player

// now start the loop:

while (numChips > 0){
// get move - not the same as get first move
// establish 1) the max to take on next move 2) numChips 3) next player


Example of output:

PLAYER 1's turn:
-1
PLAYER 1's turn:
49
PLAYER 1's turn:
10
PLAYER 2's turn:
21
PLAYER 2's turn:
20
PLAYER 1's turn:
19
PLAYER 2's turn:
0
PLAYER 2's turn:
1
PLAYER 1 WINS

Explanation / Answer

class chipGame{ private static int noOfPlayers = 2; private static int noOfChips = 50; private static int turn = 1; private static int max = 48; public static void main(String[] args){ //checking if chips available while (noOfChips > 0){ //changing the players turn if(turn == 1){ turn = 2; } else{turn = 1;} max = noOfChips>2*max?2*max:noOfChips; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote