Hi everybody. Sorry for the newbie post. I have an assignment I was just looking for some help with. I need to create a dice game that generates a random two dice throw and then gives you three tries to guess the number. I seem to be a bit stuck. I can't figure out whether to put the random generator inside the "while" loop or not. Any help would be greatly appreciated. Thanks in advance!
import javax.swing.JOptionPane;
import java.util.Random;
public class dice2
{
public static void main(String[] args)
{
int guessOne;
int guessTwo;
int roll = 0;
String userInput;
String userInput2;
userInput = JOptionPane.showInputDialog(null, "Please guess a number between 2 and 12.");
guessOne = Integer.parseInt(userInput);
if (guessOne > 12 || guessOne < 2)
{
userInput2 = JOptionPane.showInputDialog("Please make sure your guess is between 2 and 12.");
guessOne = Integer.parseInt(userInput2);
}
else
{ JOptionPane.showMessageDialog(null, "Ok...time to roll!");
Random rollOne = new Random();
int nu = 1+ rollOne.nextInt(12);
while (guessOne != nu || roll<3)
{
roll = roll + 1;
JOptionPane.showMessageDialog(null, "You rolled a " + nu);
JOptionPane.showMessageDialog(null, "Sorry...try again");
}
}
}
}
--- Update ---
Sorry I didn't explain it correctly. The game will allow you to guess a number once, and then you get three "shakes" to see if you can roll that number.