nafis nibir 8 år sedan
förälder
incheckning
4816a129fa
6 ändrade filer med 26 tillägg och 15 borttagningar
  1. Binär
      DiceyLab/Bins.class
  2. 3
    1
      DiceyLab/Bins.ctxt
  3. 5
    1
      DiceyLab/Bins.java
  4. Binär
      DiceyLab/Simulation.class
  5. 2
    2
      DiceyLab/Simulation.ctxt
  6. 16
    11
      DiceyLab/Simulation.java

Binär
DiceyLab/Bins.class Visa fil


+ 3
- 1
DiceyLab/Bins.ctxt Visa fil

@@ -6,4 +6,6 @@ comment2.params=
6 6
 comment2.target=java.lang.Integer\ getTens()
7 7
 comment3.params=key
8 8
 comment3.target=void\ increment(java.lang.Integer)
9
-numComments=4
9
+comment4.params=key
10
+comment4.target=java.lang.Integer\ getN(int)
11
+numComments=5

+ 5
- 1
DiceyLab/Bins.java Visa fil

@@ -1,7 +1,7 @@
1 1
 import java.util.TreeMap;
2 2
 public class Bins
3 3
 {
4
-    private TreeMap<Integer, Integer> bins = new TreeMap<Integer,Integer>(); 
4
+    public TreeMap<Integer, Integer> bins = new TreeMap<Integer,Integer>(); 
5 5
 
6 6
     public Bins()
7 7
     {
@@ -26,6 +26,10 @@ public class Bins
26 26
         Integer count = bins.get(key);
27 27
         bins.put(key, count + 1);
28 28
     }
29
+    
30
+    public Integer getN(int key){
31
+        return bins.get(key);
32
+    }
29 33
 
30 34
 
31 35
 }

Binär
DiceyLab/Simulation.class Visa fil


+ 2
- 2
DiceyLab/Simulation.ctxt Visa fil

@@ -4,6 +4,6 @@ comment1.params=numberOfDice\ numberOfRolls
4 4
 comment1.target=Simulation(int,\ int)
5 5
 comment2.params=
6 6
 comment2.target=void\ runSimulation()
7
-comment3.params=
8
-comment3.target=java.lang.String\ printResults()
7
+comment3.params=bin
8
+comment3.target=void\ printResults(Bins)
9 9
 numComments=4

+ 16
- 11
DiceyLab/Simulation.java Visa fil

@@ -1,31 +1,36 @@
1
-
1
+import java.util.TreeMap;
2 2
 public class Simulation
3 3
 {
4 4
     private int numberOfDice;
5 5
     private int numberOfRolls;
6
-    
6
+
7 7
     public Simulation(int numberOfDice, int numberOfRolls){
8 8
         this.numberOfDice = numberOfDice;
9 9
         this.numberOfRolls = numberOfRolls;
10 10
     }
11
-    
11
+
12 12
     public void runSimulation(){
13
-        Simulation sims = new Simulation(2, 10000);
13
+        Simulation sims = new Simulation(2, 1000000);
14 14
         Dice dice = new Dice(numberOfDice);
15 15
         Bins results = new Bins();
16
-        
16
+
17 17
         int currentRoll = 0;
18 18
         while(currentRoll < numberOfRolls){
19 19
             int result = dice.roll();
20 20
             currentRoll++;
21 21
             results.increment(result);
22 22
         }
23
+        printResults(results);
23 24
     }
24
-    
25
-    public String printResults(){
26
-        
27
-        return null;
25
+
26
+    public void printResults(Bins bin){
27
+        System.out.println("*******************************\n" +
28
+                           "Rolling 2 Dice 1,000,000 times \n" +
29
+                           "*******************************");
30
+        for (int i = 2; i <= 12; i++){
31
+            Float percent = (bin.getN(i) /1000000f);
32
+            System.out.println(String.format(i + ": " + bin.getN(i) + "%5.2f" + " : ", percent));
33
+        }
28 34
     }
29
-    
30
-    
35
+
31 36
 }