Question: In Chapter 1, you created a class called RandomGuess. In this game, players guess a number, the application generates a random number, and players determine
In Chapter 1, you created a class called RandomGuess. In this game, players guess a number, the application generates a random number, and players determine whether they were correct. Now that you can make decisions, modify the application so it allows a player to enter a guess before the random number is displayed, and then displays a message indicating whether the players guess was correct, too high, or too low. Save the file as RandomGuess2.java. (After you finish Chapter 6, you will be able to modify the application so that the user can continue to guess until the correct answer is entered.) Here is what was provided by our professor.
import javax.swing.JOptionPane; public class RandomGuess2 { public static void main(String[] args) { int guess; int result; String msg; final int LOW = 1; final int HIGH = 10; result = LOW + (int)(Math.random() * HIGH); guess = Integer.parseInt(JOptionPane.showInputDialog(null, "Try to guess my number between " + LOW + " and " + HIGH)); // Add conditional statement here // // // //********************************* JOptionPane.showMessageDialog(null,"The number is " + result + msg); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
