CSCI 1100 – Assignment #5 - Dalhousie University



CSCI 1100 – Assignment #5

Due: 8:30 am, Friday, February 15th, 2002

Your code for this program will be submitted electronically via a submit script (ready by February 13th). You must also demonstrate your program to me on February 15th between 9:30 am and 11:30 am (in Teaching Lab 3) or on Thursday, February 14th, during office hours (room 222 – 3:00-5:00 pm). If you can’t be present during either of those times, please contact me to set up an appointment.

HiLo.java

Design and implement an application that plays the HI-LO guessing game with numbers.

The first output your program should produce is your identification:

****************************

* HiLo *

* *

* Kirstie Hawkey *

* *

* B00001149 *

****************************

When the program first starts (after your identification information) and at the end of each round of the game (whether the game ended by quitting or correct guess), display the following menu of options to the user:

****************************

* 1. Play a round of HiLo. *

* 2. View game statistics. *

* 3. Quit the game *

****************************

Enter your choice:

If the user enters 1 as a choice, the program should pick a random number between 1 and 100 (inclusive), then repeatedly prompt the user to guess the number. On each guess, report to the user that they are correct, or whether the guess was high or low. Continue accepting guesses until the user guesses correctly or chooses to quit the round. Use a sentinel value to determine if the user wants to quit. Count the number of guesses and report that value to the user when the user guesses correctly.

Output should be:

Guess a number between 1 and 100: 98

Your guess is high.

Guess again or enter ‘quit’ to end the round: 57

Your guess is low.

Guess again or enter ‘quit’ to end the round: 63

Congratulations! You won round 1 in 3 guesses.

Output 2 blank lines and display menu as above.

If the user enters ‘quit’ to end the round, instead of congratulations, output:

Round 2 has been terminated. The number was 79.

If the user enters 2 as a choice, the program should output the following information: number of rounds played, number of rounds quit, number of rounds played until won, and for those rounds that were won: most guesses made, fewest guesses, and average number of guesses. For example, if the user had made 7 guesses in round 1, 3 in round 2 (before quitting), and 4 in round three, the output should be:

Total rounds played: 3

Number of rounds quit: 1

Number of rounds won: 2

Most guesses: 7

Fewest guesses: 4

Average guesses: 5.5 // output only 1 digit after

// decimal point

If the user enters 3 as a choice, the program should thank the user for playing and exit.

If the user doesn’t enter a valid menu choice, the program should prompt the user for the correct information:

You must enter a number between 1 and 3 to indicate your selection. Enter your choice:

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download