Appendix D contains information about generating random numbers. To fully understand the process, you must learn more about Java classes and methods. For now, however, you can copy the following statement to generate and use a dialog box that displays a random number between 1 and 10: JOptionPane.showMessageDialog(null,"The number is "+ (1 + (int)(Math.random() * 10))); Write a Java application that displays two dialog boxes in sequence. The first asks you to think of a number between 1 and 10. The second displays a randomly generated number; the user can see whether his or her guess was accurate. (In future chapters, you will improve this game so that the user can enter a guess and the program can determine whether the user was correct. If you wish, you also can tell the user how far off the guess was, whether the guess was high or low, and provide a specific number of repeat attempts.) Save the file as RandomGuess.java.
Appendix D contains information about generating random numbers. To fully
understand the process, you must learn more about Java classes and methods.
For now, however, you can copy the following statement to generate and use a
dialog box that displays a random number between 1 and 10:
JOptionPane.showMessageDialog(null,"The number is "+
(1 + (int)(Math.random() * 10)));
Write a Java application that displays two dialog boxes in sequence. The first asks
you to think of a number between 1 and 10. The second displays a randomly
generated number; the user can see whether his or her guess was accurate.
(In future chapters, you will improve this game so that the user can enter a
guess and the
wish, you also can tell the user how far off the guess was, whether the guess was
high or low, and provide a specific number of repeat attempts.) Save the file as
RandomGuess.java.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images