CSCI-1320 Homework 10: Guessing Game Part 1

Instructor: Todd Dole

Purpose Statement

Did someone say "loops"? This assignment will be a first step towards working with nested loops. The instructions are fairly explicit regarding the behavior the program should exhibit. That will drive how you construct your loop. For this exercise, think through whether the do-while form of the while loop would be a bit more elegant than the traditional while.

Instructions

Construct a program that will play a guessing game with the user.

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

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. Once the user guesses correctly, the game will exit.

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;

Example output and input:

                I'm thinking of a number between 1 and 100.
                What is your guess? 27
                My number is higher!
                What is your guess? 64
                My number is lower!
                What is your guess? 57
                My number is lower!
                What is your guess? 52
                You guessed it!  Great job!
            

Please submit your GuessingGame.java file through Canvas.

>