CS 157 Spring 2003         Assignment 5 – Some Basic Control – if’s –plus using an existing class.                    100 points

 

Assigned: 02/12/2003

Due: 02/19/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program.

 

Main Assignment:

We are writing a program to play a very simplified version of the game of craps. You program will use the capabilities of the Die class provided on the assignments page on my www site. The Die class provides one Die (one of a pair of dice) and methods for working with it. The class documentation file is also on the assignments page on my www site. Your program will create a pair of dice, roll the dice, figure out if the player is a winner or loser or continues playing. If continuing playing, the program will roll the dice again and figure out if the player is a winner or loser or continues playing. Since we have not covered loops, at this point the program will not continue any further. Your program will NOT need to interact with the user. In determining winning, losing etc, you need to know the rules of craps. We are only playing one way that you can play in a casino. The basic idea: Roll the dice – a total of 7 or 11 is a winner; a roll of 2,3, or 12 is a loser. Other values become the “point”. On the second roll, if 7 is rolled, we lose, if the point is rolled, we win, otherwise we keep trying. In our case, instead of keeping trying, we will stop, since we don’t know loops yet. See several examples below (Note that since the dice rolls are random, and your program is branching, you will need to test several times to know if your program is completely working!!!).

Put your name, e-mail address, and date in comments near the top.  You will need to download Die.java from my WWW page. Change the package statement in the file to be appropriate for what package you put it in, otherwise you should not have to modify the file.

Compile the program and remove any errors. Ensure that the program runs correctly. It should run correctly on any dice rolls.

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Samples:

1.

Rolled: 5 3  = 8

Rolled: 3 6  = 9

  real game would continue, but we don't know loops yet

2.

Rolled: 1 5  = 6

Rolled: 5 1  = 6

You win!!!!!!

3.

Rolled: 6 6  = 12

You lose :-(

4.

Rolled: 3 4  = 7

You win!!!

 

Hand in: