//****************************//
//*****DO NOT TOUCH THESE*****//
//****************************//
import java.util.*;
import java.io.*;
class NumberGuessingGame{
public static int num; //variable to hold randomly generated number
public static int guess; //variable to hold user inputs
public static String ans
; //variable to hold user input for y/n public static int guessnumber = 7; //variable to hold number of guesses
public static int correctguess; //variable to hold number of correct guesses
//the main method
//introduction
System.
out.
println("Welcome to the Number Guessing Game!");
//loop to allow the user to play again
ans = "y";
do{
numberGenerator();
System.
out.
println("\nI have generated a random number between 1 and 100. Please guess what the number is."); guess
= Integer.
parseInt(br.
readLine());
//TASK 2 & 3: write in the conditions for when the user's guess is too high, too low, or correct
//if the guess is correct, the user should not be able to keep guessing
if(guess > num){
System.
out.
println("Your guess is too low."); }
else if(guess < num){
System.
out.
println("Your guess is too high."); }
else if(guess < 0){
System.
out.
println("You have entered a number below 0. Would you like to try again? (y/n)"); }
else if(guess < 100){
System.
out.
println("You have entered a number above 100. Would you like to try again? (y/n)"); }
else if(guess == num){
System.
out.
println("CONGRATULATIONS! You have guessed the number correctly! Would you like to play again? (y/n)"); correctguess++;}
if(guessnumber == 6){
System.
out.
println("You have 6 guesses left."); }
else if(guessnumber == 5){
System.
out.
println("You have 5 guesses left."); }
else if(guessnumber == 4){
System.
out.
println("You have 4 guesses left."); }
else if(guessnumber == 3){
System.
out.
println("You have 3 guesses left."); }
else if(guessnumber == 2){
System.
out.
println("You have 2 guesses left."); }
else if(guessnumber == 1){
System.
out.
println("You have 1 guess left."); }
else if(guessnumber == 0){
System.
out.
println("You have ran out of guesses! Would you like to play again? (y/n)");}
//TASK 4: if the user has used up the 7 guesses, let the user know that they have run out of guesses
//they should then have the option of playing again
System.
out.
println("Play again? (y/n)"); ans = br.readLine();
if(ans.equals("n")){
System.
out.
println("Thank you for playing!"); System.
out.
println("You have gotten" + correctguess
+ "guessess right");
if(guessnumber == 7){
System.
out.
println("You have ran out of guesses! Would you like to play again? (y/n)"); }
else if(ans.equals("y")){
}
else{
System.
out.
println("Please enter y/n"); }
}
}while(ans != "y");
}
public static void numberGenerator(){
// ********* DO NOT TOUCH ************//
num = generator.nextInt(100) + 1;
// ***********************************//
}
}
//the numberGenerator method
//this method generates the random number