Procházet zdrojové kódy

All changes up to date

Lauren Green před 6 roky
rodič
revize
10da742db9

+ 1
- 0
ZCW-DiceyLab Zobrazit soubor

@@ -0,0 +1 @@
1
+LaurenResults.md

+ 3
- 3
src/main/java/Bins.java Zobrazit soubor

@@ -4,11 +4,11 @@ public class Bins {
4 4
 
5 5
     private int[] bin;
6 6
     private int numberOfDies;
7
-    HashMap<Integer,Integer> binHolder;
7
+    HashMap<Integer,Integer> binHolder = new HashMap<Integer, Integer>();//;
8 8
 
9 9
     public Bins(int numberOfDice) {
10 10
         this.numberOfDies = numberOfDice;
11
-        this.binHolder = new HashMap<Integer, Integer>();
11
+        //this.binHolder = new HashMap<Integer, Integer>();
12 12
         for (int i = numberOfDice; i <= (numberOfDice * 6); i++) {
13 13
             binHolder.put(i,0);
14 14
         }
@@ -23,7 +23,7 @@ public class Bins {
23 23
 
24 24
     public void incrementBin(int binNumber) {
25 25
 
26
-        Integer value = binHolder.get(binNumber);
26
+      int value = binHolder.get(binNumber);
27 27
         value++;
28 28
         binHolder.put(binNumber,value);
29 29
     }

+ 1
- 1
src/main/java/Dice.java Zobrazit soubor

@@ -19,7 +19,7 @@ public class Dice {
19 19
         int sumOfRolls = 0;
20 20
 
21 21
         for (int i = 1; i <= numberOfDice; i++) {
22
-            sumOfRolls = getValueOfRoll();
22
+            sumOfRolls += getValueOfRoll();
23 23
         }
24 24
 
25 25
         return sumOfRolls;

+ 1
- 1
src/main/java/MainApplication.java Zobrazit soubor

@@ -3,7 +3,7 @@ public class MainApplication {
3 3
     public static void main(String[] args) {
4 4
 
5 5
 
6
-        Simulation mySim = new Simulation(2, 500);
6
+        Simulation mySim = new Simulation(2, 1000000);
7 7
 
8 8
         mySim.runSimulation();
9 9
 

+ 3
- 2
src/main/java/Simulation.java Zobrazit soubor

@@ -37,10 +37,11 @@ public class Simulation {
37 37
 
38 38
         System.out.println("Simulation of " + this.numberOfDies + " dice tossed for " + this.numberOfTosses + " times. ");
39 39
 
40
+
40 41
         for (int i = this.numberOfDies; i <= (this.numberOfDies * 6); i++) {
41 42
 
42
-            System.out.print(String.format("%3d : ", (i)));
43
-            System.out.println(this.bin.getValueInBin(i));
43
+            System.out.println(String.format("%3d : %9d : ", (i), this.bin.getValueInBin(i)) + String.format("%.2f", (double) bin.getValueInBin(i) / this.numberOfTosses));
44
+
44 45
 
45 46
         }
46 47
     }

+ 1
- 1
src/main/test/SimulationTest.java Zobrazit soubor

@@ -25,7 +25,7 @@ public class SimulationTest {
25 25
     public void testRunSimBigToss() {
26 26
         //Given
27 27
         int numbDies = 2;
28
-        int numbTosses = 4;
28
+        int numbTosses = 100;
29 29
         Simulation sim2 = new Simulation(numbDies, numbTosses);
30 30
         int expected = numbTosses;
31 31