De'Jon Johnson 5 anni fa
parent
commit
fdedd6f5af

+ 11
- 11
README.md Vedi File

@@ -1,23 +1,23 @@
1
-# Kris-Tof Dice Toss
1
+# Kris-Tof Johnson.DeJon.Dice Toss
2 2
 
3
-Create a `Dice` class that acts like a set of N random-tossed dies.
3
+Create a `Johnson.DeJon.Dice` class that acts like a set of N random-tossed dies.
4 4
 ```
5
-Dice dice = new Dice(2); // for craps
6
-Dice dice = new Dice(5); // for yatzee
5
+Johnson.DeJon.Dice dice = new Johnson.DeJon.Dice(2); // for craps
6
+Johnson.DeJon.Dice dice = new Johnson.DeJon.Dice(5); // for yatzee
7 7
 
8 8
 Integer toss = dice.tossAndSum();
9 9
 ```
10
-make a couple unit tests for the Dice class. 
10
+make a couple unit tests for the Johnson.DeJon.Dice class. 
11 11
 
12
-Create a tracking class `Bins` that can be used to track the results of dice tosses.
12
+Create a tracking class `Johnson.DeJon.Bins` that can be used to track the results of dice tosses.
13 13
 
14 14
 ```
15
-Bins results = new Bins(2, 12); // for bins from 2..12
15
+Johnson.DeJon.Bins results = new Johnson.DeJon.Bins(2, 12); // for bins from 2..12
16 16
 Integer numberOfTens = results.getBin(10); // returns the number of tens in the 10 bin
17 17
 results.incrementBin(10); // should increment bin # 10
18 18
 
19 19
 ```
20
-make a couple unit tests for the Bins class. Your test methods should follow this template:
20
+make a couple unit tests for the Johnson.DeJon.Bins class. Your test methods should follow this template:
21 21
 
22 22
     in the tests
23 23
     Create a new Bin
@@ -27,7 +27,7 @@ make a couple unit tests for the Bins class. Your test methods should follow thi
27 27
     
28 28
     
29 29
 
30
-Create a `Simulation` class whose Constructor takes arguments:
30
+Create a `Johnson.DeJon.Simulation` class whose Constructor takes arguments:
31 31
     numberOfDies to throw
32 32
     numberOfTosses to run
33 33
 
@@ -35,7 +35,7 @@ Create a simulation where two dies are thrown *one million times*.
35 35
 Keep track of each roll by incrementing the correct Bin.
36 36
 
37 37
 ```
38
-Simulation sim = new Simulation(2, 10000);
38
+Johnson.DeJon.Simulation sim = new Johnson.DeJon.Simulation(2, 10000);
39 39
 
40 40
 sim.runSimulation();
41 41
 
@@ -53,7 +53,7 @@ the results of the sim.printResults() should be an output string that looks like
53 53
 
54 54
 ```
55 55
 ***
56
-Simulation of 2 dice tossed for 1000000 times.
56
+Johnson.DeJon.Simulation of 2 dice tossed for 1000000 times.
57 57
 ***
58 58
 
59 59
  2 :    27917: 0.03 **

+ 9
- 1
pom.xml Vedi File

@@ -8,5 +8,13 @@
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
-
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>
12 20
 </project>

+ 41
- 0
src/JavaTest/JavaTest/Johnson/DeJon/BinsTest.java Vedi File

@@ -0,0 +1,41 @@
1
+package Johnson.DeJon;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.sql.SQLOutput;
7
+import java.util.HashMap;
8
+
9
+public class BinsTest {
10
+
11
+    @Test
12
+    public void constructortest(){
13
+        //Given
14
+        Bins  bin = new Bins(2,12);
15
+
16
+        //When
17
+        Integer actual = bin.bins.get(12);
18
+
19
+        //Then
20
+        Assert.assertTrue( actual == 0);
21
+    }
22
+    @Test
23
+    public void trackTossTest(){
24
+        //Given
25
+        Bins bin = new Bins(2,12);
26
+        Dice dice = new Dice(2);
27
+        Integer tossSum = dice.tossAndSum();
28
+        bin.trackToss(tossSum);
29
+
30
+        //When
31
+
32
+        Integer actual = bin.bins.get(tossSum);
33
+
34
+        //Then
35
+        Assert.assertTrue(actual == 1);
36
+        System.out.println(bin.bins);
37
+    }
38
+}
39
+
40
+
41
+

+ 35
- 0
src/JavaTest/JavaTest/Johnson/DeJon/DIceTest.java Vedi File

@@ -0,0 +1,35 @@
1
+package Johnson.DeJon;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DIceTest {
7
+
8
+    @Test
9
+    public void getNumberOfDiceTest(){
10
+        //Given
11
+        Dice dice = new Dice(2);
12
+
13
+
14
+        //when
15
+        Integer expected = 2;
16
+        Integer actual = dice.getNumberOfDice();
17
+
18
+        //Then
19
+        Assert.assertEquals(expected, actual);
20
+
21
+    }
22
+
23
+    @Test
24
+    public void tossAndSumTest(){
25
+        //Given
26
+        Dice dice = new Dice(2);
27
+
28
+        //When
29
+        Integer actual = dice.tossAndSum();
30
+
31
+        //Then
32
+        Assert.assertTrue(actual >= 2 && actual <=12);
33
+
34
+    }
35
+}

+ 35
- 0
src/JavaTest/JavaTest/Johnson/DeJon/DieTest.java Vedi File

@@ -0,0 +1,35 @@
1
+package Johnson.DeJon;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DieTest {
7
+
8
+
9
+    @Test
10
+    public void rollTest() {
11
+        //Given
12
+
13
+        Die die = new Die();
14
+
15
+
16
+        //When
17
+
18
+        Integer actual = die.toss();
19
+
20
+
21
+        //Then
22
+        Assert.assertTrue(actual >= 1 && actual <= 6);
23
+
24
+    }
25
+
26
+    public void roll20Test(){
27
+        //Given
28
+        Die die = new Die();
29
+        //when
30
+        Integer actual = die.toss();
31
+        //Then
32
+        Assert.assertTrue(actual >= 1 &&actual<=20);
33
+
34
+    }
35
+}

+ 20
- 0
src/JavaTest/JavaTest/Johnson/DeJon/SImulationTest.java Vedi File

@@ -0,0 +1,20 @@
1
+package Johnson.DeJon;
2
+
3
+import org.junit.Test;
4
+
5
+public class SImulationTest {
6
+
7
+    @Test
8
+    public void runSimulation(){
9
+        //Given
10
+        //numberOfDies
11
+
12
+        //When
13
+
14
+    Simulation simulation = new Simulation(2, 100);
15
+    simulation.runSimulation();
16
+        System.out.println(simulation.bin.bins);
17
+        //Then
18
+
19
+    }
20
+}

+ 0
- 4
src/main/java/Bins.java Vedi File

@@ -1,4 +0,0 @@
1
-
2
-public class Bins {
3
-
4
-}

+ 0
- 4
src/main/java/Dice.java Vedi File

@@ -1,4 +0,0 @@
1
-public class Dice {
2
-
3
-
4
-}

+ 25
- 0
src/main/java/Johnson/DeJon/Bins.java Vedi File

@@ -0,0 +1,25 @@
1
+package Johnson.DeJon;
2
+
3
+import java.util.HashMap;
4
+
5
+public class Bins {
6
+
7
+    HashMap<Integer, Integer> bins;
8
+
9
+    public Bins(int min, int max){
10
+        bins = new HashMap<Integer, Integer>();
11
+        initialLizeBins(min, max);
12
+    }
13
+    private void initialLizeBins(Integer min, Integer max){
14
+        for( int i = min; i<=max; i++) {
15
+
16
+            bins.put(i, 0);
17
+        }
18
+
19
+    }
20
+
21
+    public void trackToss(int tossSum){
22
+        bins.put(tossSum, bins.get(tossSum)+1);
23
+
24
+    }
25
+}

+ 34
- 0
src/main/java/Johnson/DeJon/Dice.java Vedi File

@@ -0,0 +1,34 @@
1
+package Johnson.DeJon;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Dice {
6
+
7
+    ArrayList<Die> dice;
8
+
9
+    public Dice(Integer number) {
10
+        dice = new ArrayList<Die>();
11
+        initializedDice(number);
12
+    }
13
+
14
+    private void initializedDice(Integer number) {
15
+        for (int i = 0; i < number; i++) {
16
+            Die die = new Die();
17
+            dice.add(die);
18
+        }
19
+    }
20
+
21
+    public Integer getNumberOfDice() {
22
+        return dice.size();
23
+    }
24
+
25
+    public Integer tossAndSum() {
26
+    Integer sum = 0;
27
+        for (Die die : dice) {
28
+            sum += die.toss();
29
+
30
+        }
31
+        return sum;
32
+    }
33
+}
34
+

+ 22
- 0
src/main/java/Johnson/DeJon/Die.java Vedi File

@@ -0,0 +1,22 @@
1
+package Johnson.DeJon;
2
+
3
+import java.util.Random;
4
+
5
+public class Die {
6
+    int sides;
7
+    public Die( int sides){
8
+        this.sides = sides;
9
+
10
+    }
11
+    public Die() {
12
+        this(6);
13
+    }
14
+
15
+    public Integer toss(){
16
+
17
+        Random random = new Random();
18
+        return random.nextInt (6) +1;
19
+
20
+
21
+    }
22
+}

+ 9
- 0
src/main/java/Johnson/DeJon/Main.java Vedi File

@@ -0,0 +1,9 @@
1
+package Johnson.DeJon;
2
+
3
+public class Main {
4
+    public static void main(String[] args) {
5
+        Simulation simulation = new Simulation(2, 1000000);
6
+        simulation.runSimulation();
7
+        System.out.println(simulation.bin.bins);
8
+    }
9
+}

+ 44
- 0
src/main/java/Johnson/DeJon/Simulation.java Vedi File

@@ -0,0 +1,44 @@
1
+package Johnson.DeJon;
2
+
3
+public class Simulation {
4
+
5
+        int numberOfDies;
6
+        int numberOfTosses;
7
+        Dice dice;
8
+        public Bins bin;
9
+
10
+        public Simulation(int numberOfDies, int numberOfTosses){
11
+        this.numberOfDies = numberOfDies;
12
+        this.numberOfTosses = numberOfTosses;
13
+        this.dice = new Dice(numberOfDies);
14
+        this.bin = new Bins(numberOfDies, numberOfDies*6);
15
+
16
+        }
17
+
18
+        public void runSimulation() {
19
+
20
+                for(int i = 0; i< numberOfTosses; i++) {
21
+                     bin.trackToss(dice.tossAndSum());
22
+                }
23
+
24
+
25
+
26
+
27
+        }
28
+        public Bins returnResults(){
29
+                return this.bin;
30
+
31
+        }
32
+
33
+
34
+
35
+// Simulation sim = new Simulation(2, 10000);
36
+//
37
+//sim.runSimulation();
38
+//
39
+//sim.printResults();
40
+
41
+
42
+//    numberOfDies to throw
43
+//    numberOfTosses to run
44
+}

+ 0
- 5
src/main/java/Simulation.java Vedi File

@@ -1,5 +0,0 @@
1
-public class Simulation {
2
-
3
-
4
-
5
-}