|
@@ -2,16 +2,16 @@ import java.util.Formatter;
|
2
|
2
|
|
3
|
3
|
public class Simulation {
|
4
|
4
|
|
5
|
|
- private int diceNum=0;
|
6
|
|
- private int tossNum=0;
|
7
|
|
- private Dice dice = new Dice(diceNum);
|
8
|
|
- private Bins bin = new Bins(diceNum);
|
|
5
|
+ private int diceNum;
|
|
6
|
+ private int tossNum;
|
|
7
|
+ private Dice dice;
|
|
8
|
+ private Bins bin;
|
9
|
9
|
|
10
|
10
|
public Simulation(int diceNum, int tossNum){
|
11
|
11
|
this.diceNum = diceNum;
|
12
|
12
|
this.tossNum = tossNum;
|
13
|
|
- this.bin = bin;
|
14
|
|
- this.dice = dice;
|
|
13
|
+ this.bin = new Bins(diceNum);
|
|
14
|
+ this.dice = new Dice(diceNum);
|
15
|
15
|
}
|
16
|
16
|
|
17
|
17
|
public void runSimulation(){
|
|
@@ -20,8 +20,8 @@ public class Simulation {
|
20
|
20
|
}
|
21
|
21
|
}
|
22
|
22
|
|
23
|
|
- public void printSimulation() {
|
24
|
|
-
|
|
23
|
+ public String printSimulation() {
|
|
24
|
+ runSimulation();
|
25
|
25
|
StringBuilder result = new StringBuilder();
|
26
|
26
|
Formatter format = new Formatter(result);
|
27
|
27
|
|
|
@@ -30,16 +30,22 @@ public class Simulation {
|
30
|
30
|
result.append(" dice tossed for ");
|
31
|
31
|
result.append(tossNum);
|
32
|
32
|
result.append(" times.\n*** \n \n");
|
33
|
|
- for (int i=0; i<((diceNum*6)-(diceNum)); i++) {
|
34
|
|
- result.append(i+diceNum);
|
|
33
|
+ for (int i=0; i<((diceNum*6)-(diceNum)+1); i++) {
|
|
34
|
+ int numTimesThrown = bin.getBin(i+diceNum);
|
|
35
|
+ format.format("%2d", i+diceNum);
|
35
|
36
|
result.append(" : ");
|
36
|
37
|
format.format("%10d", bin.getBin(i+diceNum));
|
37
|
38
|
result.append(": ");
|
38
|
|
- format.format("%.2f", (double)((bin.getBin(i+diceNum))/tossNum));
|
|
39
|
+ format.format("%.2f", (double)numTimesThrown/(double)tossNum);
|
|
40
|
+ for(int j=0; j<(((double)numTimesThrown/(double)tossNum)*100); j++){
|
|
41
|
+
|
|
42
|
+ {result.append(" *");}
|
|
43
|
+ }
|
|
44
|
+ result.append("\n");
|
39
|
45
|
|
40
|
46
|
}
|
41
|
47
|
String printAns = result.toString();
|
42
|
|
- System.out.print(printAns);
|
|
48
|
+ return printAns;
|
43
|
49
|
}
|
44
|
50
|
|
45
|
51
|
|