CS 280 Spring 2008

Assignment 7 – Looping

100 points

 

Assigned: 02/27/2008

Due: 03/12/2008 (after spring break) at the start of class

 

Pre-Lab (Do Before Lab):  Bring materials – a USB for a take home copy. Plan out your GUI, tasks, objects, and events needed for program.  Plan out how you will solve the problem.

 

Main Assignment:

You are writing a program for playing a simple guessing game. The user specifies the range of possible numbers to guess (integers!). A random number within that range is generated. The player guesses a number and is told if they are high, low, or correct. They continue guessing until they get the number correct. The guessing should be via a loop-driven dialog box. Once they get the correct answer, display on the GUI the correct answer and the number of guesses they took.  See my simple sample interface below – But don’t let that constrain your creativity. Use it to help understand what I see as the inputs and outputs. The version on my www site shows screen shots from various points. You should create buttons to

1.      Play

2.      Quit

·         You’re just beginning at setting up GUIs. Don’t worry too much about making the interface nice.

·         But, if you plan on working with 5.5 or higher version of the IDE, ask me about using layouts, panels, java version, etc so that your program will work with 5.0. (Java version needs to be 1.5, NOT 1.6).

 

Hand in:

 

Control:

                You could do this game as event-driven without loops (as we did with Craps and Blackjack). Don’t do it!! This assignment is about loops. You must use a loop and dialog boxes.

 

Miscellaneous:

·         Please set the name of the project to something other than the default name (JavaApplication1, …). 

·         Put  your name in a jlabel on the GUI form OR on the Title Bar.

·         The range of numbers is specified by the user. These can be any integers. You should validate that their specified maximum is greater than their specified minimum. But, there are no other restrictions. This means, by the way that your code needs to generate a random integer within that range.

·         We are working with integers (guessing an exact double would be next to impossible). If the user enters a decimal number or any letters (in the original range or in any of their guesses), parseInt will crash. We will just let that be ok until we cover exceptions.

·         I DO want you to handle the user canceling out of the dialog box. It means that they’ve given up, I presume. You should taunt them in a user friendly way, but do let them out of the loop.

o    You MUST include some comments that explain your program in order to get full credit. 

 


Sample Interface:

 

Starting up:

 

 

Shouldn’t Work:

 

 

 

 

Getting user pick:

 

 

 

 

Feedback:

 

 

 

With results: