How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again?
Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive), then repeatedly prompt the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or chooses to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop. IN JAVA
import java.util.Scanner;
public class NumberguessingGame {
public static void main(String args[]) {
System.out.println("Welcome to the Number Guessing Game");
Scanner s = new Scanner(System.in);
int upperLimit = 100;
char choice = 'y';
do {
// create random number generator
NumberGame game = new NumberGame(upperLimit);
System.out.println("OK, I'm thinking of a number between 0 and " + upperLimit);
int guess = -1;
while (guess != game.getNumber()) {
System.out.print("Enter your Guess:");
// read the user guess
guess = Integer.parseInt(s.nextLine());
// checking for the guess
if (guess < game.getNumber()) {
// guess is low
System.out.println("Your guess is too low.");
} else if (guess > game.getNumber()) {
// guess is high
System.out.println("Your guess is too high.");
} else {
// Guess is correct
System.out.println("Correct!
" + "Bye!
" + "The number was " + game.getNumber());
System.out.println("It took " + game.getGuesses() + " tries");
break;
}
game.incrementGuessCount();
}
System.out.println("
Do you want to play again??");
choice = s.nextLine().charAt(0);
} while (choice == 'y');
s.close();
}
}
============
import java.util.Random;
public class NumberGame {
private int upperLimit, number, guesses;
public NumberGame(int upperLimit) {
this.upperLimit = upperLimit;
Random r = new Random();
this.number = r.nextInt(upperLimit);
this.guesses = 1;
}
public NumberGame() {
this(50);
}
public int getUpperLimit() {
return upperLimit;
}
public int getNumber() {
return number;
}
public int getGuesses() {
return guesses;
}
public void incrementGuessCount () {
guesses++;
}
}

Please upvote, as i have given the exact answer as asked in
question. Still in case of any concerns in code, let me know in
comments. Thanks!
How can I do this program complete with input validation so that the computer prompts the...
Hello, Could you please explain how I would complete this program with input validation to ensure that an error message will not appear if the user enters something other than an integer that is not 1-100 and later if they enter anything other than yes and no? Here is the program: Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive), then repeatedly promt the user to...
Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...
This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...
Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing. Guess my number between 1 and 1000 => 500 Too high...
I need help doing all these questions (1-6) ASAP. Keep in mind
we are only on chapter 5 of "Building Java Programs" so too
advanced code cannot be used. Please use the appropriate code coved
in the chapter and the chapters before. Thank you.?
Preview File Edit View Go Tools Window Help O 2.15 GB 00% Sun Nov 27 4:01:43 PM Q e E Ch.5 Problem Set.pdf e 2 of 2) a Search Ch.5 Problem Set.pdf l. te an interactive...
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....
Hello! we are using Python to write this
program. we are supposed to use loops in this assignment. I would
greatly appreciate the help! Thank you!
Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...
Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...
Can someone upload a picture of the code in
matlab
Write a "Guess My Number Game" program. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: 1. The program starts by printing instructions on the...
Required in JAVA language Write a program that enables a user to play number guessing games. The following is a nutshell description of a number guessing game. + a random number is generated + loop prompting the user to enter guesses until the user guesses the number or hits the maximum number of allowed guesses or enters the "quit" sentinel value The rest of this specification documents number guessing games in more detail. The documentation uses manifest constants that can...