CSCI-1320 Homework 12: Guessing Game Part 2

Instructor: Todd Dole

Purpose Statement

Did someone say "loops"? This assignment explores nested loops. The instructions are fairly explicit regarding the behavior the program should exhibit. That will drive how you construct your loops. There are places where the do-while form of the while loop would be a bit more elegant than the traditional while.

Instructions

Modify your GuessingGame program from Homework 10..

You can call your class GuessingGameII, and save it as GuessingGameII.java

Add the following requirements to your program:

  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.

Please submit your GuessingGameII.java file through Canvas.

Important Information

You should begin the process of writing this program by constructing an algorithm for the game itself. Steps you might take for the full game would be something like this:
  1. Construct an algorithm (using pseudocode or a flow chart) for playing the game.
  2. Start writing the program. Don't type in the entire game, though. Simply create a program that generates a random number in the range 1 to 100 and then displays it. Compile and test your program. (Already done in Homework 10!)
  3. Then add a prompt to have the user make a guess. Put that question in a loop that will stop only when the user's guess matches the number. Compile and test the program. (Already done in Homework 10!)
  4. After the loop print a message that congratulates the user for guessing the right number. Compile and test. (Already done in Homework 10!)
  5. Inside the loop, after the user has entered their guess, check to see if their guess was too high or too low and give them feedback appropriately. Compile and test.
  6. Save your program under another name because you now have a working program that plays the game! All that's left is adding loops to validate user input and to repeat the actions of the program. if the user wants to.
  7. Add a loop that will allow the user to play the game again. Compile and test.
  8. Replace every request for user input with an appropriate loop that validates that input. Do this one question at a time, compiling and testing after you complete each.