Problem Description

Construct a program that will play a guessing game with the user. The computer will initiate play by "thinking" of a number between 1 and 100 and then asking the user to guess it. The computer will respond by stating whether the guess was too low, too high, or correct. The user will be required to continue guessing until they have identified the number.

Having the user guess involves generating a “random” number. The following mathematical statement can be used to store such a value in the integer variable n:

  n= (int) (Math.random()*100.0)+1;

Additional requirements of the program are:

  1. Validate the user's guess to require it to be in the range 1 to 100. If they enter a value outside that range, display an error message and have them re-enter the value.
  2. After the user has guessed the secret number, congratulate them and then ask them if they want to play again. They should indicate this by entering a 'y' or an 'n'. You should validate their response by giving an error message and having them re-enter the value if they enter anything other than one of those two responses.
  3. If the user wants to play again, the computer should select another secret number and allow the user to continue guessing.