CS 161 Lab E - Guessing Game

Due Fri Oct 10 at 9:00am

Overview

In this lab, you will create a simple game to play! The game is a "number guessing game"---the computer will pick a random number between 1 and 50 (inclusive), and then the player will try to guess it. The player will have 8 guesses. The player will enter the number they guess through the keyboard, and the program will let the player know how close their guess is (if they are "hot" or "cold"). When finished, your program's output might look something like:

Welcome to the Guessing Game. I picked a number between 1 and 50. You have 8 guesses.

Number of guesses remaining 6
Guess a number: 25
Your guess is cold
Number of guesses remaining 5
Guess a number: 20
Your guess is very cold
Number of guesses remaining 4
Guess a number: 30
Your guess is warm
Number of guesses remaining 3
Guess a number: 35
Your guess is extremely warm
Number of guesses remaining 2
Guess a number: 37

Congratulations, you figured it out!

Note that I typed in the 25, 30, 35, and 37.

If you run the program again (and are less lucky/clever), the output might look like:

Welcome to the Guessing Game. I picked a number between 1 and 50. You have 8 guesses.

Number of guesses remaining 8
Guess a number: 25
Your guess is icy freezing miserable cold
Number of guesses remaining 7
Guess a number: 15
Your guess is icy freezing miserable cold
Number of guesses remaining 6
Guess a number: 30
Your guess is very cold
Number of guesses remaining 5
Guess a number: 35
Your guess is cold
Number of guesses remaining 4
Guess a number: 40
Your guess is warm
Number of guesses remaining 3
Guess a number: 45
Your guess is extremely warm
Number of guesses remaining 2
Guess a number: 50
Your guess is very warm
Number of guesses remaining 1
Guess a number: 48
Your guess is scaldingly hot!

Sorry, you couldn't guess my number!

Remember that this lab should be completed in pairs. You will need to find a different partner than you have worked with before. Be sure to review the pair programming guidelines before you begin; remember to switch off who is driving and who is navigating!

Objectives

Necessary Files

There are no necessary files for this class, but you might want to have the textbook handy!

Details

To create this program, you will need two Java classes, one to represent the SecretNumber and the other to be the main class that runs the GuessingGame.

Submitting

Make sure both your names are on both the classes (SecretNumber.java and GuessingGame.java), and upload the entire project directory to the LabE submission folder on hedwig. Only one partner needs to upload the code. Make sure you upload your work to the correct folder! The lab is due at the start of class the morning after lab.

After you have submitted your solution, log onto Moodle and submit the Lab E Partner Evaluation. Both partners need to submit evaluations!

Extensions

Grading

This assignment will be graded on approximately the following criteria: