Pārlūkot izejas kodu

working on simulation class

Kate Moore 6 gadus atpakaļ
vecāks
revīzija
7e45a8a983
2 mainītis faili ar 34 papildinājumiem un 1 dzēšanām
  1. 19
    0
      src/main/java/Bins.java
  2. 15
    1
      src/main/java/Dice.java

+ 19
- 0
src/main/java/Bins.java Parādīt failu

@@ -1,4 +1,23 @@
1
+import java.util.HashMap;
1 2
 
2 3
 public class Bins {
3 4
 
5
+    HashMap<Integer, Integer> results;
6
+
7
+    int min;
8
+    int max;
9
+
10
+    public Bins( int min, int max) {
11
+        this.results = new HashMap<Integer, Integer>();
12
+        this.min = min;
13
+        this.max = max;
14
+
15
+        for(int i = min; i <= max; i++) {
16
+            this.results.put(i, 0);
17
+        }
18
+    }
19
+
20
+    public HashMap getResults(){
21
+        return this.results;
22
+    }
4 23
 }

+ 15
- 1
src/main/java/Dice.java Parādīt failu

@@ -1,4 +1,18 @@
1
-public class Dice {
1
+public class Dice{
2 2
 
3 3
 
4
+private int numberOfDice;
5
+
6
+    public Dice(int numDice) {
7
+        this.numberOfDice = numDice;
8
+    }
9
+
10
+    public int tossAndSum() {
11
+        int total = 0;
12
+
13
+        for(int i = 0; i< this.numberOfDice; i++) {
14
+            total += (int) (Math.floor(Math.random() *6 ) + 1);
15
+        }
16
+        return total;
17
+    }
4 18
 }