________________________________________________________
Professor I. Rudowsky CIS 26 MW12
Homework
Assignment 3 Due
________________________________________________________
During
the lecture, we discussed the class Die which simulated rolling one die 6,000
times.
|
UML diagram for Class Die
//Code for Class
Die public class Die { private int face; public void rollDie() {face= (int)(1+Math.random()*6);} public int getFace() { return face; } } |
|
(a)
Using class Die, write a class named RollTwoDie which
simulates the rolling of two dice, myDie1 and myDie2, each rolled 6,000 times.
For each of the 6,000 repetitions, roll myDie1 and myDie2 and add the two
values together. The sum should be between 2 and 12. Keep track of how many of
each sum appears and print out the count for each of the values between 2 and
12 after all 6,000 repetitions have completed.
(b) The
sum of 7 can come from the following pairs of myDie1 and myDie2 - (6, 1), (1,
6), (2,5), (5,2),
(3,4) and (4,3). While doing part (a), keep track of how many times each
of these pairs occurred and print the results.
The sum of these pairs should equal the number of times the total number
of times the sum 7 appeared.