## Post Lab 8: Rolling a Pair of Dice

### Due Friday, November 5, 2004

In this assignment you will write a PairOfDice class and then use it in a program with a loop.

The PairOfDice class should have the following instance data: two Die objects. Use the class Die.java from your textbook. The methods in the PairOfDice class should be:

• a constructor with no parameters - the constructor will instantiate each Die object.
• a method roll that rolls each die and returns the sum of the face values. The method should have no parameter. (NOTE: You need to use methods in the Die here and in other methods.)
• a method isDoubles that returns true if the face values on the two dice are the same ("doubles") and false otherwise.
• a toString method that returns the PairOfDice object as a string in the following format (assuming the first die is a 2 and the second a 5):
```       [ 2 : 5 ]
```
• a method getTotalRoll that returns the total of the face values on the two dice.

Write a program PlayGame that does the following:

• Instantiates a PairOfDice object.
• Rolls the dice and saves the value of the roll (call this point).
• Print out the first roll (appropriately labeled).
• Next keep rolling the dice until you roll point again. Count the number of times you roll and the number of times that you get doubles. Print out each roll. Note that this needs a loop. The general structure will be as follows:
```       // Set up - roll the dice to get the next roll and initialize the
// counting variables (one for number of rolls and one for doubles)

while the next roll is not equal to point
{
//  print the current dice

//  increment the count for the number of rolls

//  if the roll is doubles increment the doubles counter

//  get the next roll (roll again!)
}
```

• After the loop print out the number of rolls it took to match point (appropriately labeled) and the number of doubles that were rolled while you were rolling the dice.

Hand In:

• Hard copy of PairOfDice.java and PlayGame.java.
• Tar you post lab directory that contains all of your files and email it to your instructor with the subject cs120 post8.