errors
i got the following code (driver class):
import javax.swing.*;
publicclass SnakeEyes
{
publicstaticvoid main (String[] args)
{
String play, rolls, faces;
int snakeEyes = 0, rollNum = 0, facesNum = 0;
double num1, num2;
play = JOptionPane.showInputDialog(null,"do you want to play SnakeEyes (y/n)?");
do
{
try
{
rolls = JOptionPane.showInputDialog(null,"how many rolls do you want");
rollNum = Integer.parseInt(rolls);
if (rollNum <= 0)
JOptionPane.showMessageDialog(null,"ERROR: Number less that 0");
}
catch (NumberFormatException e)// ERROR HANDLING: INPUT NOT CORRECT
{
JOptionPane.showMessageDialog(null,"ERROR - Invalid Input: Input new values");
}
Die die1 =new Die();//6 sided die
try
{
faces = JOptionPane.showInputDialog(null,"how many faces do you want (2-20)");
facesNum = Integer.parseInt(faces);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"ERROR - Invalid Input: Input new values");
}
Die die2 =new Die(facesNum);
for (int roll = 1; roll <= rollNum; roll++)//Loop for number of rolls
{
die1.roll();
num1 = die1.getFaceValue();
die2.roll();
num2 = die2.getFaceValue();
if (num1 == 1 && num2 == 1)//Snakes eyes
snakeEyes = snakeEyes + 1;//If snake eyes, add 1
}
JOptionPane.showMessageDialog(null,"Ratio: " + (double)snakeEyes/rollNum);
JOptionPane.showMessageDialog(null,"SnakeEyes: " + snakeEyes);
JOptionPane.showMessageDialog(null,"Number of rolls " + rollNum);
play = JOptionPane.showInputDialog(null,"do you want to play SnakeEyes (y/n)?");
}
while(play.equals("y"));
}
}
You see where i have put "if (rollNum <= 0)" and then the error message comes up....
How do i then after the user presses 'OK' that the user re inputs the number of rolls?
Thanks

