-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathSimulation.java
More file actions
57 lines (50 loc) · 1.67 KB
/
Simulation.java
File metadata and controls
57 lines (50 loc) · 1.67 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
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import java.io.PrintStream;
import java.util.Arrays;
public class Simulation {
public static void main(String[] args) {
run(2, 1000000);
}
private Dice dice;
private Bins bin;
private Integer numOfToss;
private Integer numOfDice;
private Integer min;
private Integer max;
public Simulation(Integer numOfDice, Integer numOfToss) {
this.numOfToss = numOfToss;
this.numOfDice = numOfDice;
this.min = numOfDice;
this.dice = new Dice(numOfDice);
this.bin = new Bins(numOfDice, numOfDice * 6);
}
public static void run (Integer numOfDice, Integer numOfToss) {
Dice dice = new Dice(numOfDice);
Bins bin = new Bins(numOfDice, numOfDice * 6);
for (int i = 0; i < numOfToss; i++) {
dice.tossAndSum();
bin.incrementBin(dice.tossAndSum());
}
// System.out.println(Arrays.toString(Bins.values));
// System.out.println("2's: " + Bins.values[0] + " : %.2d");
printer();
}
public static void printer () {
String jawner = "";
String jawnski = "";
for (int i = 0; i < Bins.values.length; i++) {
if (i < 3) {
jawnski = " ";
} else {
jawnski = "";
}
Double result = Bins.values[i] / 1000000.0;
jawner += (i + 2) + ": " + Bins.values[i] + jawnski + " : " + String.format("%.2f", result) + " ";
for (int j = 0; j < (result * 100) - 1; j++) {
jawner += "*";
}
jawner += "\n";
}
System.out.println(jawner);
}
}