|
|
@@ -1,31 +1,36 @@
|
|
1
|
|
-
|
|
|
1
|
+import java.util.TreeMap;
|
|
2
|
2
|
public class Simulation
|
|
3
|
3
|
{
|
|
4
|
4
|
private int numberOfDice;
|
|
5
|
5
|
private int numberOfRolls;
|
|
6
|
|
-
|
|
|
6
|
+
|
|
7
|
7
|
public Simulation(int numberOfDice, int numberOfRolls){
|
|
8
|
8
|
this.numberOfDice = numberOfDice;
|
|
9
|
9
|
this.numberOfRolls = numberOfRolls;
|
|
10
|
10
|
}
|
|
11
|
|
-
|
|
|
11
|
+
|
|
12
|
12
|
public void runSimulation(){
|
|
13
|
|
- Simulation sims = new Simulation(2, 10000);
|
|
|
13
|
+ Simulation sims = new Simulation(2, 1000000);
|
|
14
|
14
|
Dice dice = new Dice(numberOfDice);
|
|
15
|
15
|
Bins results = new Bins();
|
|
16
|
|
-
|
|
|
16
|
+
|
|
17
|
17
|
int currentRoll = 0;
|
|
18
|
18
|
while(currentRoll < numberOfRolls){
|
|
19
|
19
|
int result = dice.roll();
|
|
20
|
20
|
currentRoll++;
|
|
21
|
21
|
results.increment(result);
|
|
22
|
22
|
}
|
|
|
23
|
+ printResults(results);
|
|
23
|
24
|
}
|
|
24
|
|
-
|
|
25
|
|
- public String printResults(){
|
|
26
|
|
-
|
|
27
|
|
- return null;
|
|
|
25
|
+
|
|
|
26
|
+ public void printResults(Bins bin){
|
|
|
27
|
+ System.out.println("*******************************\n" +
|
|
|
28
|
+ "Rolling 2 Dice 1,000,000 times \n" +
|
|
|
29
|
+ "*******************************");
|
|
|
30
|
+ for (int i = 2; i <= 12; i++){
|
|
|
31
|
+ Float percent = (bin.getN(i) /1000000f);
|
|
|
32
|
+ System.out.println(String.format(i + ": " + bin.getN(i) + "%5.2f" + " : ", percent));
|
|
|
33
|
+ }
|
|
28
|
34
|
}
|
|
29
|
|
-
|
|
30
|
|
-
|
|
|
35
|
+
|
|
31
|
36
|
}
|