|
@@ -1,5 +1,42 @@
|
|
1
|
+import java.util.Scanner;
|
|
2
|
+
|
1
|
3
|
public class Simulation {
|
|
4
|
+ private static int numDice = 2;
|
|
5
|
+ private static int numberOfTosses = 1000000;
|
|
6
|
+ private static double percentage;
|
|
7
|
+ private static double stars;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+ public static void main(String[] args) {
|
|
11
|
+ Dice dice = new Dice();
|
|
12
|
+ Bins numberOfBin = new Bins();
|
|
13
|
+ int sum = 0;
|
|
14
|
+
|
|
15
|
+ for (int i = 0; i < numberOfTosses; i++) {
|
|
16
|
+ sum = dice.rollDice(numDice, 0);
|
|
17
|
+ ++numberOfBin.bin[sum];
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ //Print bins
|
|
22
|
+ for (int i = 2; i < 13; i++) {
|
|
23
|
+ //Percentage of rolls
|
|
24
|
+ percentage = ((numberOfBin.bin[i]) / numberOfTosses);
|
|
25
|
+ stars = (((double) numberOfBin.bin[i]) / numberOfTosses) * 100;
|
|
26
|
+
|
|
27
|
+// System.out.println(numberOfBin.bin[i]);
|
|
28
|
+// System.out.println("Bin " + i + ":\t" + numberOfBin.bin[i] + ":\t" + percentage);
|
|
29
|
+// System.out.println("Bin " + i + ":\t" + numberOfBin.bin[i] + ":\t" + percentage);
|
|
30
|
+ System.out.printf("%2d :\t%6d:\t%.2f ", i, numberOfBin.bin[i], (double) numberOfBin.bin[i] / numberOfTosses);
|
|
31
|
+// System.out.println((((double) numberOfBin.bin[i]) / numberOfTosses)*100);
|
|
32
|
+// System.out.println((int)stars);
|
|
33
|
+ for (int j = 0; j < stars; j++) {
|
|
34
|
+ System.out.print("*");
|
|
35
|
+ }
|
|
36
|
+ System.out.println(" \n");
|
2
|
37
|
|
|
38
|
+ }
|
|
39
|
+ }
|
3
|
40
|
|
4
|
41
|
|
5
|
42
|
}
|