ITEC 120 Back to Assignment index page
   
Assignment 2 - Rollin', Rollin', Rollin'
Submit your program to your instructor's directory in the ITEC120 folder on neelix.

Description: Sam was determined to win his high school science fair project. He was fascinated by probability and dice. He gave a pair of dice to two of his friends, George and Sally, and had them each roll their pair of dice. He noticed that sometimes they would both get the same roll, for example, a six and a one. He also noticed that sometimes they rolled the same number, but their rolls were different, for example, George might roll a 4 and a 3, while Sally rolled a 5 and a 2, both totaling 7. Sam wondered how likely it was for George and Sally to get the same roll exactly, and how likely it was for George and Sally to roll the same number. So, Sam set up an experiement to determine this likelihood. He talked George and Sally into rolling their dice 1000 times, and he counted the number of times they rolled the same number, and the number of times they got the very same roll. After an intense weekend of dice rolling, he proudly took his recorded numbers to his teacher, who said "I admire your fortitude, Sam. The next step is to repeat your experiment a number of times to to see if you get the same results."

Sam expressed to you his concern that George and Sally would not agree to any more dice rolling, and he didn't think he had enough friends left to repeat his experiment too many more times. Plus he was kind of tired of looking at dice himself. "No worries!" you exclaimed, "I can write a program to repeat your experiment 100 times if you like."

You will write a program to repeat Sam's experiement 100 times. Sam's experiement is to roll 2 pairs of dice 1000 times, and count the number of rolls with the same points, and the number of same rolls. Report the highest, lowest, and average number of same rolls (in 1000 rolls), and the highest, lowest, and average number of same number rolls (in 1000 rolls).

Sample output:

Simulation of two pair of dice.
Statistics for 100 trials of 1000 rolls each.

-------------SAME ROLL-----------
Most same rolls:            66
Fewest same rolls:          33
Average same rolls :        51.03

------SAME NUMBER ROLLED---------
Most same number rolls:     143
Fewest same number rolls:   90
Average same number rolls:  112.84

You will write a driver program (program2.java) and a class file (PairOfDice.java). Here's a suggested UML diagram for your PairOfDice class:

PairOfDice
- face1 : int
- face2 : int
+ PairOfDice( )
+ roll ( ) : int
+ isSameRoll ( PairOfDice other ) : boolean
+ toString ( ) : String

The roll method returns the total of the roll of the pair of dice (as an int).

The isSameRoll returns true if the two rolls are exactly the same. Notice that the isSameRoll() method takes another PairOfDice object as its parameter. Refer to page 244 in the book for a discussion and example of this.

You might want to write a program to first perform Sam's experiement once (1000 rolls) and count the number of same rolls and same number rolls. Once you have that working, try to get the process to repeat 100 times, adding the necessary logic to figure out then highs, los, and averages.

Please remember to put PairOfDice.java and program2.java inside the RU06 folder in your folder on neelix. (RU05 is for labquiz3)