Lab 1790 - Craps

Description

In this lab, you will create two classes: a Dice class and a Craps class. The dice class models a six-sided die for the game of craps.

Part 1: Dice class

Create a class called Dice that simulates an N-sided die and the actions that can be performed with it. Methods should allow the client to roll the die (returning a number between 1 and N) and also determine the number of die sides. In addition, your class should keep an internal record of the number of rolls and a running sum of those rolls, both of which can be reported to and reset by the client.

Though the craps game uses six-sided dice, the Dice class should be able to handle dice with an arbitrary number of sides. A two sided die is equivalent to a coin flip.

Part 2: Craps class

In a separate file called Craps.java, write a method that plays a round of craps using your Dice class (craps uses two 6-sided dice). This method should return true if the player wins and false otherwise.

Specific requirements:
(1) You must implement a private function private int rollDice() that returns the sum of the two rolled dice.
(2) The method that plays the game must be public boolean playGame().

Here are the rules to craps:

    * If the first roll is 7 or 11, the player wins.
    * If the first roll is 2, 3 or 12, the player loses.
    * If the player doesn't win or lose on the first roll, the player 
      continues rolling until...
          - the player rolls 7, in which case the player loses.
          - the player rolls the value of the first roll, in which case the player wins. 

Once you have the craps round implemented, write a test program that simulates 100,000 rounds and reports the number of wins, number of losses, and the percentage of wins.

Deliverables

Complete Dice.java, Craps.java and CrapsTest.java. After your program run of 100,000 rounds, copy and paste the output back into the source code for CrapsTest.java as a multi-line comment before submitting your code for grading.


Copyright © 2010 by Asylum Computer Services LLC Return to CS Labs