Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
Guessing Range
This class helps the user play a simple guessing game by keeping track of what the user has learned from previous guesses. It is the solution to an assignment given out in the fall of 2003. The relevant part of the origianl assignment follows:

Write a class GuessingRange that does just what GuessingGame (another program on this site) did, but with prompts that includes the range i..j so far, where i is "one more than" the highest guess below the answer, and j is "one less than" the lowest guess above the answer:

Your guess was too high. You know that the number is in the range i..j, inclusive. Guess again.

Your guess was too low. You know that the number is in the range i..j, inclusive. Guess again.

Of course, replace i and j with actual numbers, and think carefully about what exact values they should have.

After 1 guess, you only know i or j. In this case, use an open-ended range, of the form i.. or ..j.

When the user finishes, tell them (using JOptionPane.showMessageDialog):
You're right! You used x guesses.
where x is the number of guesses, including the correct guess.

Download files: GuessingRange.java
Areas: Introduction to loops.


GuessingRange.java
1import javax.swing.*;
2
3/**
4 * A game for guessing a number, where the user is told the range the
5 * solution is in based on their guesses.
6 */
7public class GuessingRange {
8
9  /** The number to be guessed */
10  private int solution;
Displaying 10 of 73 lines
View full source


Question 1
What happens if the user's first guess is too low?
Hints Solution

Question 2
Why is upper initialized to ""?
Hints Solution