Working with the Dice and MultiDice Classes

 

First use the Dice Class to solve problems 1 and 2. Then design the MultiDice Class as discussed in class. Then use MultiDiceTest.java to check whether your class is working properly. After that is successful, do #'s 3 and 4:

 

Use the Dice Class for programs 1 and 2

 

1.   Write a program that will allow you to roll an 8-sided die 1000 times and keep track of the results. Display them as follows.

 

#
Count
Percent
1
125
12.5%
2
125
12.5%
3
125
12.5%
4
125
12.5%
5
125
12.5%
6
125
12.5%
7
125
12.5%
8
125
12.5%

 

 

2.  

 

 

 

 

 

 

 

 

 

2. The Game of Craps: Write a program using the Dice Class to play the Game of Craps (see rules below)

 

1.         You roll two dice and take the sum
2.         If the sum is 7 or 11, you WIN.
            If the sum is 2, 3 or 12, you LOSE.
            If the sum is 4, 5, 6, 8, 9 or 10, that number becomes the “point”, and game continues.
3.         Continue to roll until one of the following occurs:

Four Example Games with Desired Output:


5 + 6 = 11 (you win!)
-------------------------------------

1 + 2 = 3 (you lose!)
-------------------------------------

3 + 5 = 8 (8 is your point, roll again)
2 + 4 = 6 (roll again)
5 + 4 = 9 (roll again)
5 + 2 = 7 (you lose!)
-------------------------------------

2 + 2 = 4 (4 is your point, roll again)
2 + 1 = 3 (roll again)
1 + 3 = 4 (you win!)
-------------------------------------

 

 

Use the MultiDice Class for programs 3 and 4

 

3.   In the game of Yahtzee, the ultimate goal is to roll 5 dice and have them all come up the same. In the real game, you get three tries, but in this simulation, we will estimate the chances of rolling once and having all 5 dice come up the same number. To do so, roll 5 dice 100,000 times and keep track of how many times all 5 dice come up the same. Display each roll that results in a Yahtzee and the final results as a count and a percent.

   

Final results should be displayed as follows:

{2, 2, 2, 2, 2} Yahtzee!

{5, 5, 5, 5, 5} Yahtzee!

etc...

You got a Yahtzee 15 times(.015%)

 

 

4.   Write a program that will allow you to roll two 4-sided dice 1000 times and keep track of the results. Display them as follows.

 

#
Count
Percent
2
100
10.0%
3
100
10.0%
4
200
20.0%
5
200
20.0%
6
200
20.0%
7
100
10.0%
8
100
10.0%