forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceSimulation3.java
More file actions
67 lines (57 loc) · 2.44 KB
/
DiceSimulation3.java
File metadata and controls
67 lines (57 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
This class simulates rolling a pair of dice 10,000 times and
counts the number of times doubles of are rolled for each different
pair of doubles.
*/
import java.util.Random; //to use the random number generator
public class DiceSimulation3
{
public static void main(String[] args)
{
final int NUMBER = 10000; //the number of times to roll the dice
//a random number generator used in simulating rolling a dice
Random generator = new Random();
int die1Value; // number of spots on the first die
int die2Value; // number of spots on the second die
int snakeEyes = 0; // number of times snake eyes is rolled
int twos = 0; // number of times double two is rolled
int threes = 0; // number of times double three is rolled
int fours = 0; // number of times double four is rolled
int fives = 0; // number of times double five is rolled
int sixes = 0; // number of times double six is rolled
int count = 0;
Random rand = new Random ();
Random rand2 = new Random ();
do
{
count=count+1;
die1Value = rand.nextInt(6)+1;
die2Value = rand2.nextInt(6)+1;
if ((die1Value == 1)&&(die2Value == 1))
{snakeEyes++;}
else if ((die1Value == 2)&&(die2Value == 2))
{twos++;}
else if ((die1Value == 3)&&(die2Value == 3))
{threes++;}
else if ((die1Value == 4)&&(die2Value == 4))
{fours++;}
else if ((die1Value == 5)&&(die2Value == 5))
{fives++;}
else if ((die1Value == 6)&&(die2Value == 6))
{sixes++;}
}
while (count<NUMBER);
System.out.println ("You rolled snake eyes " + snakeEyes +
" out of " + count + " rolls.");
System.out.println ("You rolled double twos " + twos +
" out of " + count + " rolls.");
System.out.println ("You rolled double threes " + threes +
" out of " + count + " rolls.");
System.out.println ("You rolled double fours " + fours +
" out of " + count + " rolls.");
System.out.println ("You rolled double fives " + fives +
" out of " + count + " rolls.");
System.out.println ("You rolled double sixes " + sixes +
" out of " + count + " rolls.");
}
}