ITEC 120 LAB 18 Back to Lab index page

Number Guesser, object oriented

Rewrite the number guesser project, which you did in lab 17, in an object oriented way.

You'll have 2 files - a driver which will create and use one or more GuessingGame objects (and the other file defines the GuessingGame class) .

A GuessingGame object will have 3 pieces of instance data:

The GuessingGame class will have these methods:

The driver will do all the i/o (intput/output), that is, prompt the user and read the user's input. The driver will create a new GuessingGame each time the user wishes to play again.

The program can work the same way it did before (or you could enhance it). The big difference is in the design of the program.

For the upper bound, the driver can either prompt the user for the upper bound or, the upper bound could be "hard-coded" into the driver (could be a constant).

After you get your program working, add two static variables to the GuessingGame class -

Initialize each to 0. Figure out where these variables need to be incremented. Add a static method stats which returns a String containing nicely formatted statistics: The total number of games played, the total number of guesses (tries) made, and the average number of guesses made until the user correctly guessed the number. Call this method in your driver (after the user decides to stop playing... at the end).