浏览代码

dice first push

Nick Satinover 6 年前
父节点
当前提交
8a5704f057
共有 1 个文件被更改,包括 49 次插入0 次删除
  1. 49
    0
      src/main/java/Simulation.java

+ 49
- 0
src/main/java/Simulation.java 查看文件

@@ -1,5 +1,54 @@
1
+import java.util.Formatter;
2
+
1 3
 public class Simulation {
2 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);
9
+
10
+    public Simulation(int diceNum, int tossNum) {
11
+        this.diceNum = diceNum;
12
+        this.tossNum = tossNum;
13
+        this.bin = bin;
14
+        this.dice = dice;
15
+    }
16
+
17
+    public void runSimulation() {
18
+        for (int i = 0; i < tossNum; i++) {
19
+            bin.incrementBin(dice.tossAndSum());
20
+        }
21
+    }
22
+
23
+    public int getNumOfDice(){
24
+        return diceNum;
25
+    }
26
+
27
+    public int getNumOfTosses(){
28
+        return tossNum;
29
+    }
30
+
31
+    public String printSimulation(){
32
+        runSimulation();
33
+        StringBuilder result = new StringBuilder("");
34
+        Formatter formatter = new Formatter(result);
3 35
 
36
+        result.append("***\n Simulation of " + diceNum + " dice tossed for " + tossNum + " times.\n*** \n \n");
4 37
 
38
+        for (int i = 0; i < ((diceNum * 6) - (diceNum) + 1); i++){
39
+            int numofThrows = bin.getBin(i + diceNum);
40
+            formatter.format("%2d", i + diceNum + " : ");
41
+            formatter.format("%10d", bin.getBin(i + diceNum) + " : ");
42
+
43
+            for (int x = 0; x < ( (double)numofThrows/ (double)tossNum ) * 100; x++){
44
+                result.append(" *");
45
+            }
46
+            result.append("\n");
47
+        }
48
+        return result.toString();
49
+    }
5 50
 }
51
+
52
+
53
+
54
+