/** * This program will play a simple guessing game with the user. * The program will generate a random integer between 1 and 10 (inclusive). * Ask the user to guess the number and then check the guess with the generated number. * All I/O will be done using dialog boxes. * * @author Anthony Larrain * Fall 2001, csc211 * */ import javax.swing.JOptionPane; class NumberGuess{ public static void main( String [] arg){ // This statement will produce an integer 1-10(inclusive) int randNum = (int)(Math.random() * 10 + 1); String getGuess = JOptionPane.showInputDialog("I am thinking of a number between 1-10,\n\n What is it ???"); int guess = Integer.parseInt(getGuess); String response; if (guess == randNum){ response = " Great guess you are correct "; }else{ response = "Sorry, incorrect \n\n The number is.. " + randNum; } JOptionPane.showMessageDialog(null, response); System.exit(0); } }