CS 232: Data Structures and Problem Solving

Spring 1999

Assignment 1

Java Review and Class Specification

Due Monday February 1

Part 1

Create a class called PairOfDice that simulates a pair of N-sided dice and the actions that can be done with them. In particular, your class should provide methods that allow a client to roll the dice, retrieve the sum of the dice, and determine whether doubles was rolled. The class should also keep an internal record of the running total and the number of times the dice were rolled, which can be reported to and reset by the client.

For constructing the PairOfDice, first create its specification using the javadoc commenting conventions. Before you continue, review your specification with the instructor. Then, write the implementation. Finally, thoroughly test your class using the static main method.

Part 2

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

Here are the rules to craps:

Once you have the craps round implemented, write code in your main method that simulates 1000 rounds and reports the percentage of wins.

Submission

For submitting your lab assignment turn in the following hard copies:

Make sure you have documented the code as described in class.