Jessica Campbell 6 vuotta sitten
vanhempi
commit
ec74c9aa33
3 muutettua tiedostoa jossa 41 lisäystä ja 11 poistoa
  1. 1
    1
      src/main/java/Bins.java
  2. 12
    0
      src/main/java/JessResults.md
  3. 28
    10
      src/main/java/Simulation.java

+ 1
- 1
src/main/java/Bins.java Näytä tiedosto

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

+ 12
- 0
src/main/java/JessResults.md Näytä tiedosto

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 Näytä tiedosto

1
+import javax.sound.midi.Soundbank;
1
 import java.util.Formatter;
2
 import java.util.Formatter;
2
 import java.util.HashMap;
3
 import java.util.HashMap;
3
 import java.util.Map;
4
 import java.util.Map;
8
     private Dice dice;
9
     private Dice dice;
9
     private Bins bins;
10
     private Bins bins;
10
     private int numberOfDie;
11
     private int numberOfDie;
12
+    protected Simulation simulation;
11
 
13
 
12
     public Simulation(int numberOfDie, int numberOfThrows) {
14
     public Simulation(int numberOfDie, int numberOfThrows) {
13
         this.numberOfThrows = numberOfThrows;
15
         this.numberOfThrows = numberOfThrows;
14
         this.dice = new Dice(2);
16
         this.dice = new Dice(2);
15
         this.bins = new Bins(numberOfDie, numberOfDie * 6);
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
         public void runSimulation() {
19
         public void runSimulation() {
26
             for (int i = 0; i < numberOfThrows; i++) {
20
             for (int i = 0; i < numberOfThrows; i++) {
27
                 int value = dice.diceRoll();
21
                 int value = dice.diceRoll();
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
     public static void main(String[] args) {
49
     public static void main(String[] args) {
34
-        Simulation sim = new Simulation(2, 10);
50
+        Simulation sim = new Simulation(2, 10000);
35
         sim.runSimulation();
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