For some coding practice I am trying to do some extra problems on the side and cannot figure this one out and was hoping if you could do this one, and use javax.swing, along with the sample code from our textbook: import javax.swing.JOptionPane; public class Count21 { public static void main(String[] args) { int player; int computer; String msg; int total = 0; final int FACTOR = 4; final int HIGH = 3; final int LOSING_VAL = 21; final String inputMsg = "\nInput a number between 1 and " + HIGH;
For some coding practice I am trying to do some extra problems on the side and cannot figure this one out and was hoping if you could do this one, and use javax.swing, along with the sample code from our textbook:
import javax.swing.JOptionPane;
public class Count21
{
public static void main(String[] args)
{
int player;
int computer;
String msg;
int total = 0;
final int FACTOR = 4;
final int HIGH = 3;
final int LOSING_VAL = 21;
final String inputMsg = "\nInput a number between 1 and " + HIGH;
player =
Integer.parseInt(JOptionPane.showInputDialog(null, inputMsg));
while(player < 1 || player > HIGH)
player = Integer.parseInt(JOptionPane.showInputDialog(null "Number must be between 1 and " + HIGH + "\nPlease reenter"));
total += player;
Two people play the game of Count 21 by taking turns entering a 1, 2,
or 3, which is added to a running total.
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.
Step by step
Solved in 3 steps