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

Two people play the game of Count 21 by taking turns entering a 1, 2, or 3, whic

ID: 3800912 • Letter: T

Question

Two people play the game of Count 21 by taking turns entering a 1, 2, or 3, which is
added to a running total. The player who adds the value that makes the total exceed
21 loses the game. Create a game of Count 21 in which a player competes against the
computer, and program a strategy that always allows the computer to win. On any
turn, if the player enters a value other than 1, 2, or 3, force the player to reenter the
value. Save the game as Count21.java.

How can you "program a strategy that always allows the computer to win"?

Explanation / Answer

You can use the following logic to make the use reenter the value incase he enters the value other than 1,2, or 3

System.out.println("Enter the turn value");
Scanner scanner = new Scanner(System.in);
int turn = scanner.nextLine();
if(turn>3 && turn<1)
{
System.out.println("Please ReEnter the turn value");
}

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