In: Computer Science
import javax.swing.JOptionPane;
public class RandomGuess
{
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));
if(guess == result)
msg = "\nRight!";
else
if(guess < result)
msg = "\nYour guess was too low";
else
msg = "\nYour guess was too high";
JOptionPane.showMessageDialog(null,"The number is " + result +
msg);
}
}
Edit the file attached for players to guess a number, the application to generate a random number, and for players to determine if they guessed correctly. Add a loop to continue prompting the user for the number, stating if it is high or low, until the correct value is entered by the user. Once the user guesses correctly the number, display a count of the attempts made to get correct value. Save changes
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// RandomGuess.java
import javax.swing.JOptionPane;
public class RandomGuess {
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);
while(true)
{
guess =
Integer.parseInt(JOptionPane.showInputDialog(null,
"Try to guess my number
between " + LOW + " and " + HIGH));
if (guess ==
result)
{
msg = "\nRight!";
break;
}
else if (guess
< result)
msg = "\nYour guess was too low";
else
msg = "\nYour guess was too high";
JOptionPane.showMessageDialog(null,msg);
}
JOptionPane.showMessageDialog(null,
"The number is " + guess+msg);
}
}
__________________________
Output:
_______________Could you plz rate me well.Thank You