|
@@ -1,5 +1,65 @@
|
|
1
|
+import com.sun.javafx.binding.StringFormatter;
|
|
2
|
+
|
|
3
|
+import java.util.Formatter;
|
|
4
|
+
|
1
|
5
|
public class Simulation {
|
2
|
6
|
|
|
7
|
+ private Dice dice;
|
|
8
|
+ private Bins diceBin;
|
|
9
|
+ private int tosses;
|
|
10
|
+ private int diceNum;
|
|
11
|
+
|
|
12
|
+ public Simulation(int diceNum, int tosses) {
|
|
13
|
+
|
|
14
|
+ this.dice = new Dice(diceNum);
|
|
15
|
+ this.diceBin = new Bins(diceNum);
|
|
16
|
+ this.tosses = tosses;
|
|
17
|
+ this.diceNum = diceNum;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+ public void runSimulation() {
|
|
24
|
+ for (int i = 0; i < tosses ; i++) {
|
|
25
|
+ diceBin.incrememtBin(dice.tossAndSum());
|
|
26
|
+
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ public String printResults() {
|
|
33
|
+ runSimulation();
|
|
34
|
+ StringBuilder simulation = new StringBuilder();
|
|
35
|
+ Formatter adjust = new Formatter();
|
|
36
|
+
|
|
37
|
+ simulation.append("```\n***\nSimulation of ");
|
|
38
|
+ simulation.append(diceNum);
|
|
39
|
+ simulation.append(" dice tossed for ");
|
|
40
|
+ simulation.append(tosses);
|
|
41
|
+ simulation.append(" times.\n***\n\n");
|
|
42
|
+
|
|
43
|
+ for (int i = 2; i <(diceNum * 6); i++) {
|
|
44
|
+ int timesThrown = diceBin.getBin(diceNum);
|
|
45
|
+ simulation.append(i + " : ");
|
|
46
|
+ adjust.format("%10d", diceBin.getBin(i) );
|
|
47
|
+ simulation.append(": ");
|
|
48
|
+ adjust.format("%.2f", (double)timesThrown/(double)tosses);
|
|
49
|
+ for(int j=0; j<(((double)timesThrown/(double)tosses)); j++) {
|
|
50
|
+
|
|
51
|
+ {simulation.append(" *");}
|
|
52
|
+
|
|
53
|
+ }
|
|
54
|
+ simulation.append("\n```");
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ String result = simulation.toString();
|
|
59
|
+ return result;
|
|
60
|
+
|
|
61
|
+ }
|
|
62
|
+
|
3
|
63
|
|
4
|
64
|
|
5
|
65
|
}
|