April Rivera 6 anni fa
parent
commit
8f7b5a02af
4 ha cambiato i file con 66 aggiunte e 4 eliminazioni
  1. 19
    0
      pom.xml
  2. 6
    1
      src/main/java/Bins.java
  3. 24
    3
      src/main/java/Simulation.java
  4. 17
    0
      src/test/java/DiceTest.java

+ 19
- 0
pom.xml Vedi File

@@ -7,6 +7,25 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>1.8</source>
17
+                    <target>1.8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>RELEASE</version>
27
+        </dependency>
28
+    </dependencies>
10 29
 
11 30
 
12 31
 </project>

+ 6
- 1
src/main/java/Bins.java Vedi File

@@ -1,9 +1,12 @@
1
+
1 2
 import java.util.Map;
2 3
 import java.util.TreeMap;
3 4
 
5
+
6
+
4 7
 public class Bins {
5 8
 
6
-   static  Map<Integer, Integer> diceRollTotalsAndFrequency = new TreeMap<Integer, Integer>();
9
+   static  Map<Integer, Integer> diceRollTotalsAndFrequency = new TreeMap<>();
7 10
 
8 11
    public static void persistDiceRoll(Integer diceRollValue){
9 12
 
@@ -16,6 +19,8 @@ public class Bins {
16 19
        }
17 20
        diceRollTotalsAndFrequency.put(diceRollValue, currentValue);
18 21
 
22
+
23
+
19 24
        //diceRollTotalsAndFrequency.put(diceRollValue,
20 25
        // diceRollTotalsAndFrequency.get(diceRollValue) == null ?
21 26
        // 1 : diceRollTotalsAndFrequency.get(diceRollValue) + 1);

+ 24
- 3
src/main/java/Simulation.java Vedi File

@@ -1,13 +1,34 @@
1
+import java.util.Map;
2
+
1 3
 public class Simulation {
2 4
 
3
-    public static void main(String[] args){
5
+
6
+    public static void main(String[] args) {
4 7
 
5 8
         Dice dice = new Dice();
6 9
 
7
-        for(int i = 0; i < 10; i ++){
10
+        for (int i = 0; i < 1000000; i++) {
8 11
             dice.rollDiceAndPersistValues();
9 12
         }
10
-    }
11 13
 
14
+//        String results = Bins.diceRollTotalsAndFrequency.toString().replaceAll("[\\[\\](){}]", "");
15
+        for(Map.Entry entry : Bins.diceRollTotalsAndFrequency.entrySet()){
16
+            System.out.println(entry +"\n");
17
+        }
12 18
 
19
+    }
13 20
 }
21
+
22
+//         2 :    27917: 0.03 **
23
+//         3 :    55422: 0.06 *****
24
+//         4 :    83457: 0.08 ********
25
+//         5 :   110961: 0.11 ***********
26
+//         6 :   139098: 0.14 *************
27
+//         7 :   166977: 0.17 ****************
28
+//         8 :   138386: 0.14 *************
29
+//         9 :   111102: 0.11 ***********
30
+//         10 :    83367: 0.08 ********
31
+//         11 :    55799: 0.06 *****
32
+//         12 :    27514: 0.03 **
33
+
34
+

+ 17
- 0
src/test/java/DiceTest.java Vedi File

@@ -0,0 +1,17 @@
1
+import org.junit.Before;
2
+import org.junit.Test;
3
+
4
+import java.util.Random;
5
+
6
+public class DiceTest{
7
+
8
+    @Before
9
+    public void setUp(){
10
+        Random random = new Random();
11
+    }
12
+    @Test
13
+    public void rollDiceAndGiveValueTest(){
14
+
15
+    }
16
+
17
+}