Lab 3 Console Craps Game
This lab requires 3 classes. Read this lab IN ITS ENTIRETY before beginning.
Class: Dice
This class should be similar to the
Coin class, with instance variable
private int numberOfSides;
and methods
public int roll() //returns
a random number between 1 and the numberOfSides
public int numberOfRolls() // returns how many times this die has been rolled
public int getNumberOfSides() // returns the number of sides
public String toString() // formats a string to represent this die
Class: Craps
It should have private instance variables :
private int itsPoint;
private Dice itsDie1, itsDie2;
and public methods
public Craps(); // the constructor
public void play();
Rules for craps (how the play method should
work)
A player rolls two dice. Each die has six faces. These
faces contain 1, 2, 3, 4, 5 and 6. After the dice have come to rest, the sum
of the
spots on the two upward faces is calculated. If the sum is 7 or 11 on the first
throw, the player wins. If the sum is 2, 3 or 12 on the
first throw (called “craps”), the player loses(i.e. the “house”
wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then that sum
becomes the player’s “point.” To win, you must continue rolling
the dice until you “make your point.” The player loses by rolling
a 7
before making the point.
You will need a while loop for playing the game. You
use a while loop when you do not know how many times to repeat a loop. In this
case,
you want to keep rolling the dice until you either get a 7 (you lose) or your
point (you win). If you use the words, “as long as”, it helps
get the condition correct. As long as the sum is not a 7 and you have not rolled
your point (the same sum as the first roll), keep rolling.
That would look like :
while (diceSum != 7 &&
diceSum != point)
{
}
Be sure you put System.out.println's in to see each roll and print the results.
This should only have a main method.
public static void main (String[ ]
args)
{
Craps game = new Craps();
game.play();
}