GuessingGame.java
import java.util.Scanner;
import java.util.Random;
public class GuessingGame {
private static final int MIN_NUMBER =
1;
private static final int MAX_NUMBER = 205;
private static final int QUIT_VALUE = -1;
private static final int MAX_GAMES = 4;
private static final int MAX_GUESSES = 10;
private static final int HINT_THRESHOLD =
5;
private static final int BACKDOOR_VALUE =
-314;
private static final String NOPE_MSG =
"nope...";
private static final String NOPE_NOPE_MSG
=
"you've already guessed that wrong
guess...";
private static final String INVALID_INPUT_BEGIN
=
"*** invalid input -- ";
private static final String
INVALID_INPUT_LESS_MIN_MSG =
INVALID_INPUT_BEGIN + "must be
greater than " + (MIN_NUMBER - 1);
private static final String
INVALID_INPUT_GREATER_MAX_MSG =
INVALID_INPUT_BEGIN + "must be less
than " + (MAX_NUMBER + 1);
private static final String INVALID_INPUT_YN_MSG
=
INVALID_INPUT_BEGIN + "must be n or
y";
private static final String WINNER_MSG =
"you're a winner... # of guesses:
";
private static final String LOSER_MSG =
"too many guesses entered... the
number was ";
private static final String QUITTER_MSG =
"you're a quitter... the number was
";
private static final String MAX_GAMES_PLAYED_MSG
=
"you've played the maximum number ("
+ MAX_GAMES + ") of games";
private static final String ENTER_GUESS_PROMPT
=
"enter a guess between " +
MIN_NUMBER + " and " + MAX_NUMBER +
" (" + QUIT_VALUE + " to quit):
";
private static final String PLAY_AGAIN_PROMPT
=
"Do you want to play again (n or y)?
";
private static final String BOLD_BEGIN = "***
";
private static final String BOLD_END = "
***";
private static final String PLAY_MSG = " playing
the CSC" + MAX_NUMBER +
" guessing game." + BOLD_END;
private static final String WELCOME_MSG =
BOLD_BEGIN + "Hello! Have fun" +
PLAY_MSG;
private static final String THANKS_MSG =
BOLD_BEGIN + "Thanks for" +
PLAY_MSG;
static Random rng = new
Random(System.currentTimeMillis());
static Scanner stdin = new
Scanner(System.in);
static Scanner scan = new
Scanner(System.in);
static int guess;
static int numberOfGames = 0;
static int numberOfWins = 0;
static int numberOfLoses = 0;
static boolean endStart = true; // Check if this
boolean is used
public static void
main(String[] args) {
PlayGame();
PostGame();
EndGame();
}
public static boolean
check(int item, int[] chekarray){
for (int i = 0; i < chekarray.length - 1; i++){
if (chekarray[i] == item)
return true;
}
return false;
}
public static void
PlayGame() {
int guessCounter = 0;
int n = MIN_NUMBER + rng.nextInt(MAX_NUMBER);
int[] history = new int[10];
boolean found = false;
System.out.println(WELCOME_MSG);
boolean test = true;
do{
found = false;
System.out.println();
System.out.print(ENTER_GUESS_PROMPT);
guess = stdin.nextInt();
if (check(guess, history)){
found = true;
}
history[guessCounter] = guess;
guessCounter = guessCounter + 1;
if(guess < MIN_NUMBER && guess != BACKDOOR_VALUE
&&
guess != QUIT_VALUE){
if (found) {
System.out.print(NOPE_NOPE_MSG + "\n");
guessCounter--;
} else {
System.out.println(INVALID_INPUT_LESS_MIN_MSG + "\n");
guessCounter--;
}
}
if(guess > MAX_NUMBER){
if (found) {
System.out.print(NOPE_NOPE_MSG + "\n");
guessCounter--;
} else {
System.out.println(INVALID_INPUT_GREATER_MAX_MSG +
"\n");
guessCounter--;
}
}
// Giving the user the answer
if(guess == BACKDOOR_VALUE){
System.out.println(n);
guessCounter--;
}
// Quiting the round and giving the chance to end the game
if(guess == QUIT_VALUE){
System.out.println((QUITTER_MSG + n) + "\n" +
PLAY_AGAIN_PROMPT);
numberOfLoses++;
String val = scan.next();
if(val.equalsIgnoreCase("y")){
numberOfGames++;
PlayGame();
}
if(val.equalsIgnoreCase("n")){
System.out.println(THANKS_MSG);
test = false;
PostGame();
break;
}
}
// Correct guess on the last try
if(guessCounter == MAX_GUESSES && guess == n){
numberOfGames++;
System.out.println(WINNER_MSG + guessCounter);
numberOfWins++;
System.out.println(PLAY_AGAIN_PROMPT);
String val = scan.next();
if(val.equalsIgnoreCase("y"))
PlayGame();
if(val.equalsIgnoreCase("n")){
System.out.println(THANKS_MSG);
test = false;
PostGame();
break;
}
}
// Max games
if(numberOfGames == MAX_GAMES){
System.out.println(MAX_GAMES_PLAYED_MSG);
test = false;
PostGame();
break;
}
// Max guesses
if(guessCounter == MAX_GUESSES){
numberOfGames++;
System.out.println(LOSER_MSG+ n + "\n" +PLAY_AGAIN_PROMPT);
numberOfLoses++;
String val = scan.next();
if(val.equalsIgnoreCase("y"))
PlayGame();
if(val.equalsIgnoreCase("n")){
System.out.println(THANKS_MSG);
test = false;
PostGame();
break;
}
}
// Guessing in the range of the bonds
if(guess > MIN_NUMBER || guess < MAX_NUMBER){
if (found) {
System.out.print(NOPE_NOPE_MSG + "\n");
guessCounter -= 1;
} else {
System.out.print(NOPE_MSG);
}
if(guess == n){
numberOfGames++;
System.out.println(WINNER_MSG + guessCounter);
numberOfWins++;
System.out.println(PLAY_AGAIN_PROMPT);
String val = scan.next();
if(val.equalsIgnoreCase("y"))
PlayGame();
if(val.equalsIgnoreCase("n")){
System.out.println(THANKS_MSG);
test = false;
PostGame();
break;
}
}
}
// Giving hints after 5 tries until the max # of guesses
if(guessCounter == HINT_THRESHOLD ||
guessCounter == (HINT_THRESHOLD + 1) ||
guessCounter == (HINT_THRESHOLD + 2) ||
guessCounter == (HINT_THRESHOLD + 3) ||
guessCounter == (HINT_THRESHOLD + 4) ||
guessCounter == (HINT_THRESHOLD + 5)){
if(guess != n && guess > n){
System.out.println("lower");
}
if(guess != n && guess < n){
System.out.println("higher");
}
}
}
while(guess > MIN_NUMBER || guess < MAX_NUMBER);
}
// Post game
information
public static void
PostGame() {
int winningPct = 0;
System.out.print("Played: " + numberOfGames + ";" +
" Won: " + numberOfWins + ";" +
" Lost: " + numberOfLoses + ";");
if(numberOfGames != 0){
System.out.println(" winningPct: " +
(winningPct = numberOfWins/numberOfGames));
EndGame();
}
else{
winningPct =0;}
EndGame();
}
// Ending the game
public static void
EndGame(){
}
}

Required in JAVA language Write a program that enables a user to play number guessing games....
Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...
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...
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 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...
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...
python question
Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during 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...
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...
Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...
on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...