Jessica Campbell 6 lat temu
rodzic
commit
ec74c9aa33

+ 1
- 1
src/main/java/Bins.java Wyświetl plik

@@ -4,7 +4,7 @@ public class Bins {
4 4
 
5 5
     private int startingPoint;
6 6
     private int endingPoint;
7
-    private HashMap<Integer, Integer> recordOfRolls;
7
+    protected HashMap<Integer, Integer> recordOfRolls;
8 8
 
9 9
     public Bins(int startingPoint, int endingPoint) {
10 10
         recordOfRolls = new HashMap<>();

+ 12
- 0
src/main/java/JessResults.md Wyświetl plik

@@ -0,0 +1,12 @@
1
+2:     297  0.02970 ***
2
+3:     558  .05580  *****
3
+4:     832  .08320  ********
4
+5:     1145  .11450 ************
5
+6:     1361  .13610 **************
6
+7:     1697  .16970 *****************
7
+8:     1340  .1340  **************
8
+9:     1105  .11050 ************
9
+10:     862  .08620 **********
10
+11:     530  .0530 ******
11
+12:     273  .0273 ***
12
+

+ 28
- 10
src/main/java/Simulation.java Wyświetl plik

@@ -1,3 +1,4 @@
1
+import javax.sound.midi.Soundbank;
1 2
 import java.util.Formatter;
2 3
 import java.util.HashMap;
3 4
 import java.util.Map;
@@ -8,20 +9,13 @@ public class Simulation {
8 9
     private Dice dice;
9 10
     private Bins bins;
10 11
     private int numberOfDie;
12
+    protected Simulation simulation;
11 13
 
12 14
     public Simulation(int numberOfDie, int numberOfThrows) {
13 15
         this.numberOfThrows = numberOfThrows;
14 16
         this.dice = new Dice(2);
15 17
         this.bins = new Bins(numberOfDie, numberOfDie * 6);
16 18
     }
17
-
18
-//
19
-//    public void simulationToString() {
20
-//        StringBuilder sb = new StringBuilder();
21
-//        for (Map.Entry entry : bins.incrementBin) {
22
-//            System.out.println(entry + "\n");
23
-//        }
24
-//    }
25 19
         public void runSimulation() {
26 20
             for (int i = 0; i < numberOfThrows; i++) {
27 21
                 int value = dice.diceRoll();
@@ -30,10 +24,34 @@ public class Simulation {
30 24
             }
31 25
         }
32 26
 
27
+    public String simulationToString() {
28
+        StringBuilder sb = new StringBuilder();
29
+        for (Integer keys:bins.recordOfRolls.keySet()) {
30
+            sb.append(keys +":     "+ bins.recordOfRolls.get(keys) + "\n");
31
+        }
32
+
33
+        return sb.toString();
34
+    }
35
+
36
+    public String getPercentage(){
37
+       StringBuilder sb = new StringBuilder();
38
+        Double sum = 0.0;
39
+        for (Integer i : bins.recordOfRolls.values()){
40
+             sum += i;
41
+        }
42
+        for (Integer keys : bins.recordOfRolls.values()) {
43
+            Double percent = keys / sum;
44
+            sb.append(percent);
45
+        }
46
+        return sb.toString();
47
+    }
48
+
33 49
     public static void main(String[] args) {
34
-        Simulation sim = new Simulation(2, 10);
50
+        Simulation sim = new Simulation(2, 10000);
35 51
         sim.runSimulation();
36
-//        sim.simulationToString();
52
+       System.out.println(sim.simulationToString());
53
+        System.out.println(sim.getPercentage());
54
+
37 55
     }
38 56
 
39 57