CS 280 Spring 2008

Assignment 6 – Branching (along with using an existing class)

100 points

 

Assigned: 02/20/2008

Due: 02/27/2008 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.  Download, unzip and familiarize yourself with the Die Class that I’m providing. Plan out how you will solve the problem.

 

Main Assignment:

You are writing a program for playing Craps (one aspect of – there are actually lots of different kinds of bets in Craps).  Rules are included below. We are still a little bit away from being able to do the full job, so pay attention to what I’m asking for. Also note that you will need to gain an understanding of the provided Die class. The provided class will be in a zip file on Blackboard, along with documentation for the class.  A quick introduction is included below. 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 paper version of this assignment shows a couple of screen shots from different points running my program. The version on my www site shows 5 screen shots from various points. We definitely want to control what the user can do at any given time (mostly by enabling and disabling buttons and jTextFields). Details are given below. You should create buttons to

1.      Start a new player – will enable sign in

2.      Play – will “validate” starting bankroll and if valid will enable playing and betting

3.      Bet (“Go” in my interface) – will “validate” bet, and if valid will roll and display dice, and determine if player wins, loses, or if winning/losing is not determined yet (see rules below)

4.      Ok (or Continue) – will continue game when game is not won or lost yet (see rules below)

5.      Exit – quits the game

·         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:

 

Craps Rules (“most interesting variation”):

·         7 or 11 wins

·         2,3, or 12 loses

·         Anything else – becomes “point” –  the new target

·         7 – loses

·         Point – wins

·         Anything else – keep rolling – aiming for the same point (point doesn’t change!)

 

Control:

                This game is not well suited to “Event-Driven” programming because most of the things a user could do would be “wrong” at a given point of time. We definitely want to control what the user can do at any given time mostly by enabling and disabling buttons and jTextFields. Details:

 

Provided Class:

 

Miscellaneous:

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

·         Add your name to mine in the jlabel at the top of the GUI form OR on the Title Bar.

·         The minimum bet is $5.00. Use a symbolic constant (final) for this.

·         The maximum bet is the player’s current balance.

·         The minimum starting bankroll is the minimum bet. There is no maximum.

·         Display dice rolls as they occur in a jTextArea. If a game lasts several rolls, we should be able to see all of the rolls (see my sample interface).

·         Inform the user when they have won or lost with a dialog box. Also, update totals – number of games played, number of wins, number of losses, current balance, and change (difference) from their starting bankroll.

·         If the user enters letters into their bet or their starting bankroll, parseDouble will crash – no worries – we won’t deal with this until we cover exceptions.

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

 


Sample Interface:

 

Starting up:

 

 


New Player Clicked:

 

 


Invalid Bankroll:

 

 

After Clicking Play:

 

 


Bet more than he had:

 

 

After Bet and Go (didn’t win or lose on first roll):

 

 

 


Win by hitting point:

 

 

 


Losing by hitting 7 when trying for point:

 

 

 


Winning on first roll:

 

 

 


Losing on first roll:

 

 

 


Flat Broke:

 

 

 


New Player again (probably would have made sense to clear the player name and starting bankroll too):