IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one and 100. Then it will ask the user to make a guess as to what the number is. If the guess is incorrect, but is within the range of 1 to 100, the user will be told if it is higher or lower and then asked to guess again. If the guess was outside the valid range or not readable by Scanner class, a message to “try again” will be given. The range of acceptable guesses should change with each new piece of information. Here is a partial output of the program.
Enter 1 to 100: 45
Good guess but your value is too low
Enter 46 to 100: 87
Good guess but your value is too high
Enter 46 to 86 : 25
Value is outside of range
Enter 46 to 86: fifty
Inputs must be numerical
Enter 46 to 86: 57
That is the correct number! It took you 3 valid guesses, 5 in total.
When each guess happens, the hidden answer, this new guess, and the current min and max values will be sent to a static method called high_or_low (4 input parameters). This method will attempt to return an integer value that is the difference from the correct value. This value will help you determine if value guessed is higher(positive), lower(negative), or zero(found) then the correct answer. If the guess was outside the current range allowed (this starts with 1 to 100 but changes with each valid guess) an exception should be thrown from the method. The main method should have a loop and try and catch blocks needed to force the user to reenter for any inputs that are not the correct answer(including bad input or out of range), forcing them to reenter. Continue until the number is finally guessed and then report the total number of valid guesses and total overall guesses. Exceptions must be used and caught and NO BREAK STATEMENTS
Thanks for the question.
Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.
Thank You !
===========================================================================
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
public class GuessingGame {
private static int high_or_low(int hiddenAnswer, int userGuess, int min, int max) {
if (userGuess == hiddenAnswer) return 0;
if (userGuess < min || userGuess > max) {
throw new IllegalArgumentException("Try again");
}
return hiddenAnswer - userGuess;
}
public static void main(String[] args) {
Random random = new Random();
Scanner scanner = new Scanner(System.in);
int hiddenAnswer = 1 + random.nextInt(100);
// System.out.println("hiddenAnswer = " + hiddenAnswer);
int min = 1;
int max = 100;
int difference = 100;
int userGuess = -1;
int validGuesses = 0;
int totalGuesses = 0;
do {
System.out.print("Enter " + min + " to " + max + ": ");
try {
totalGuesses += 1;
userGuess = scanner.nextInt();
difference = high_or_low(hiddenAnswer, userGuess, min, max);
validGuesses+=1;
if (difference < 0) {
System.out.println("Good guess but your value is too high");
max = userGuess;
} else if (difference > 0) {
System.out.println("Good guess but your value is too low");
min = userGuess;
} else {
System.out.println("That is the correct number! It took you "+
(validGuesses-1)+" valid guesses, "+totalGuesses+" in total.");
}
} catch (InputMismatchException e) {
System.out.println("Inputs must be numerical");
scanner.nextLine();
} catch (IllegalArgumentException e) {
System.out.println("Try again");
}
} while (difference != 0);
}
}
=========================================================================

let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the answer.
Thanks!
===========================================================================
IN BASIC JAVA and using JAVA.UTIL.RANDOM write a program will randomly pick a number between one...
Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....
Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...
(c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...
Java code Guessing Game Refinement. (The user thinks of a
number and the program guesses it) Program should be able to guess
correctly in 7 tries or lower.
Initialize a variable that represents the lowest possible
number to 0 (what type should this be?)
Initialize a variable that represent the highest possible
number to 100 (what type should this be?)
Initialize a Boolean variable that represents if we’ve
achieved the correct guess to false
Initialize a variable in which to...
Create a HTML with Java Script such that you input a number between 222 and 333. Then the user needs to guess the number. If the user’s guess is higher than the number, the program should display “Too high, try again.” If the user’s guess is lower than the number, the program should display “Too low, try again.” If the difference is less than 10, it should also mention "too close". When the user guesses the number, the program should...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...
Java Guessing Game Class The class will generate a random number of 1 to 15, and then check to see if the user guessed the number correctly. If the number is incorrect, the user should have the chance to guess again, until they guess the right number or they guess 10 times. The class method should keep track of the number of guesses the user has had, and return this value. The class should have one constructors, a default and...
For this lab you will write a Java program using a loop that will play a simple Guess The Number game. Th gener e program will randomly loop where it prompt the user for a ate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a r has guessed the correct number, the program will end with a message indicating how many guesses it took to get the right answer and a...
Solve Question using While loops-MATLAB Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.