Lab 3: Guessing Game

In this lab you will use selection and repetition structures to create a simple game.

  1. import java.lang.Math; // import the Math class for random numbers
  2. Generate a random integer between 1 and 100 using (int) (100*Math.random()) + 1.
  3. Prompt the user to guess an integer between 1 and 100 inclusive, or 0 to quit.
  4. Get the user's input from the keyboard. See ConsoleString.java or KeyboardString.java.
  5. Test and inform the user whether his or her guess is too high, too low or correct.
  6. Keep looping until the user guesses correctly or enters 0.
  7. If the user enters 0, display the correct answer and quit.
  8. Compile, run and debug the program.
  9. Try to answer this mathematics question (and add to the source code in a comment):
    What is the maximum number of intelligent guesses needed to correctly guess the number?
  10. Send the source code to the instructor as an attachment with subject java lab3.