Browse Source

{jaejoson DiceyLab effort}

Jacqueline Joson 5 years ago
parent
commit
b05858a98b
6 changed files with 106 additions and 1 deletions
  1. 9
    0
      pom.xml
  2. 32
    0
      src/main/java/Bins.java
  3. 17
    0
      src/main/java/Dice.java
  4. 14
    0
      src/main/java/DiceTest.java
  5. 9
    0
      src/main/java/Main.java
  6. 25
    1
      src/main/java/Simulation.java

+ 9
- 0
pom.xml View File

@@ -8,5 +8,14 @@
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <!-- https://mvnrepository.com/artifact/junit/junit -->
13
+        <dependency>
14
+            <groupId>junit</groupId>
15
+            <artifactId>junit</artifactId>
16
+            <version>4.12</version>
17
+            <scope>test</scope>
18
+        </dependency>
19
+    </dependencies>
11 20
 
12 21
 </project>

+ 32
- 0
src/main/java/Bins.java View File

@@ -1,4 +1,36 @@
1 1
 
2 2
 public class Bins {
3
+    int [] bins;
4
+    int min;
5
+    int binNumber;
6
+
7
+
8
+    public Bins(int min, int max) {
9
+        this.min = min;
10
+        this.bins = new int[max - min + 1];
11
+    }
12
+
13
+    public void addUpCount(int binNumber) {
14
+        int counter = 0;
15
+        int i = 0;
16
+        for (i = 0; i < bins.length; i++) {
17
+            if (binNumber == i) {
18
+                counter++;
19
+                bins[i] = counter;
20
+            }
21
+            }
22
+    }
23
+
24
+
25
+    public int getCount(int binNumber) {
26
+        int i = 0;
27
+        int getOccurrences = 0;
28
+        for (i = 0; i < bins.length; i++) {
29
+            if (binNumber == i) {
30
+                getOccurrences = bins[i];
31
+            }
32
+        }
33
+        return getOccurrences;
34
+    }
3 35
 
4 36
 }

+ 17
- 0
src/main/java/Dice.java View File

@@ -1,4 +1,21 @@
1
+import java.util.Random;
2
+
3
+
4
+
1 5
 public class Dice {
6
+    int dieNumber;
2 7
 
8
+    public Dice(int dieNumber) {
9
+        this.dieNumber = dieNumber;
10
+    }
3 11
 
12
+    public int tossAndAdd(int dieNumber) {
13
+        int sum = 0;
14
+        for (int i = 0; i <= dieNumber; i++) {
15
+            Random die = new Random();
16
+            sum += 1 + (die.nextInt(6));
17
+        }
18
+            //System.out.print(sum);
19
+        return sum;
20
+    }
4 21
 }

+ 14
- 0
src/main/java/DiceTest.java View File

@@ -0,0 +1,14 @@
1
+//import org.junit.Assert;
2
+//import org.junit.Test;
3
+//
4
+//public class DiceTest {
5
+//
6
+//        @Test
7
+//        public void tossAndAddTest() {
8
+//            Dice one = new Dice(1);
9
+//            int total = one.tossAndAdd();
10
+//            boolean acceptable = true;
11
+//            Assert.assertTrue(acceptable);
12
+//        }
13
+//    }
14
+

+ 9
- 0
src/main/java/Main.java View File

@@ -0,0 +1,9 @@
1
+public class Main {
2
+    public static void main (String [ ] args) {
3
+        Simulation sim = new Simulation(2, 10000);
4
+        Dice dice = new Dice(2);
5
+        Bins bin = new Bins(2, 12);
6
+        sim.runSimulation();
7
+        sim.printResults();
8
+    }
9
+}

+ 25
- 1
src/main/java/Simulation.java View File

@@ -1,5 +1,29 @@
1
+
2
+
1 3
 public class Simulation {
2 4
 
5
+    int numOfDice;
6
+    int numberOfRolls;
7
+
8
+
9
+    public Simulation(int numOfDice, int numberOfRolls) {
10
+        this.numOfDice = numOfDice;
11
+        this.numberOfRolls = numberOfRolls;
12
+    }
13
+
14
+
15
+        Dice dice = new Dice(2);
16
+        Bins bin = new Bins(2, 12);
17
+
18
+
19
+        public void runSimulation () {
20
+            for (int i = 0; i < numberOfRolls; i++) {
21
+                bin.addUpCount(dice.tossAndAdd(numOfDice));
22
+            }
23
+        }
3 24
 
25
+    public void printResults () {
26
+           Simulation sim = new Simulation(2, 10000);
27
+        }
4 28
 
5
-}
29
+    }