Sfoglia il codice sorgente

Have compeleted up until simulations

Akeem Cherry 5 anni fa
parent
commit
22f7d00741

BIN
.DS_Store Vedi File


BIN
src/.DS_Store Vedi File


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

@@ -1,60 +0,0 @@
1
-import org.junit.Test;
2
-
3
-public class Bins {
4
-
5
-    Bins(int min, int max) {
6
-
7
-
8
-        Bins results = new Bins(2, 12);
9
-        Integer numberOfTwo = results.getBin(2);
10
-        results.incrementBin(2);
11
-
12
-        new Bins(2, 12);
13
-        Integer numberOfThree = results.getBin(3);
14
-        results.incrementBin(3);
15
-
16
-        new Bins(2, 12);
17
-        Integer numberOfFour = results.getBin(4);
18
-        results.incrementBin(4);
19
-
20
-        new Bins(2, 12);
21
-        Integer numberOfFive = results.getBin(5);
22
-        results.incrementBin(5);
23
-
24
-        new Bins(2, 12);
25
-        Integer numberOfSix = results.getBin(6);
26
-        results.incrementBin(6);
27
-
28
-        new Bins(2, 12);
29
-        Integer numberOfSeven = results.getBin(7);
30
-        results.incrementBin(7);
31
-
32
-        new Bins(2, 12);
33
-        Integer numberOfEight = results.getBin(8);
34
-        results.incrementBin(8);
35
-
36
-        new Bins(2, 12);
37
-        Integer numberOfNine = results.getBin(9);
38
-        results.incrementBin(9);
39
-
40
-        new Bins(2, 12);
41
-        Integer numberOfTen = results.getBin(10);
42
-        results.incrementBin(10);
43
-
44
-        new Bins(2, 12);
45
-        Integer numberOfEleven = results.getBin(11);
46
-        results.incrementBin(11);
47
-
48
-        new Bins(2, 12);
49
-        Integer numberOfTvelve = results.getBin(12);
50
-        results.incrementBin(12);
51
-    }
52
-
53
-    private Integer getBin(int i) {
54
-        return null;
55
-    }
56
-
57
-    private void incrementBin(int i) {
58
-    }
59
-
60
-}

+ 0
- 0
src/main/java/Cherry/Akeem/AkeemResults.md Vedi File


+ 23
- 0
src/main/java/Cherry/Akeem/Bins.java Vedi File

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

+ 32
- 0
src/main/java/Cherry/Akeem/Dice.java Vedi File

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

+ 24
- 0
src/main/java/Cherry/Akeem/DiceTest.java Vedi File

@@ -0,0 +1,24 @@
1
+package Cherry.Akeem;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DiceTest {
7
+
8
+    @Test
9
+    public void GetNumberOfDiceTest(){
10
+        Dice dice = new Dice(2);
11
+        Integer expected = 2;
12
+        Integer actual = dice.getNumberOfDice();
13
+        Assert.assertEquals(expected,actual);
14
+    }
15
+
16
+    @Test
17
+    public void TossAndSumTest(){
18
+        Dice dice = new Dice(2);
19
+        Integer actual = dice.tossAndSum();
20
+        Assert.assertTrue(actual >= 2 && actual <= 12);
21
+
22
+    }
23
+
24
+}

+ 23
- 0
src/main/java/Cherry/Akeem/Die.java Vedi File

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

+ 24
- 0
src/main/java/Cherry/Akeem/Simulation.java Vedi File

@@ -0,0 +1,24 @@
1
+package Cherry.Akeem;
2
+
3
+public class Simulation {
4
+
5
+    Integer numberOfDies;
6
+    Integer numberOfTosses;
7
+    Dice dice;
8
+    Bins bins;
9
+
10
+    public Simulation (Integer numberOfDies, Integer numberOfTosses){
11
+        this.numberOfDies = numberOfDies;
12
+        this.numberOfTosses = numberOfTosses;
13
+    }
14
+
15
+    public void runSimulation(){
16
+        for (Integer i = 0; i < numberOfTosses; i++){
17
+            bins.trackTosses(dice.tossAndSum());
18
+        }
19
+    }
20
+
21
+    public Bins returnResults(){
22
+        return this.bins;
23
+    }
24
+}

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

@@ -1,26 +0,0 @@
1
-public class Dice {
2
-
3
-    private int die1;
4
-    private int die2;
5
-
6
-    public Dice() {
7
-        roll();
8
-    }
9
-
10
-    public void roll() {
11
-        die1 = (int) (Math.random()*6) + 1;
12
-        die2 = (int) (Math.random()*6) + 1;
13
-    }
14
-
15
-    int getDie1() {
16
-        return die1;
17
-    }
18
-
19
-    int getDie2() {
20
-        return die2;
21
-    }
22
-
23
-    int getTotal() {
24
-        return die1 + die2;
25
-    }
26
-}

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

@@ -1,27 +0,0 @@
1
-public class Simulation {
2
-
3
-
4
-    public Simulation(int i, int i1) {
5
-
6
-    }
7
-
8
-    public static void main(String[] args) {
9
-            Simulation sim = new Simulation(2, 10000);
10
-
11
-            Dice dice;
12
-            int rollCount;
13
-
14
-            dice = new Dice();
15
-            rollCount = 0;
16
-
17
-            for (int i = 1; i <= 10000; i++) {
18
-                dice.roll();
19
-                System.out.println("The roll total is " + dice.getTotal());
20
-                rollCount++;
21
-            }
22
-            System.out.println(sim);
23
-
24
-        }
25
-
26
-
27
-}

+ 26
- 0
src/tests/java/Cherry/Akeem/BinsTest.java Vedi File

@@ -0,0 +1,26 @@
1
+package Cherry.Akeem;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class BinsTest {
7
+    @Test
8
+    public void ConstructorTest(){
9
+        Bins bins = new Bins(2,12);
10
+        Integer actual = bins.bins.get(12);
11
+        System.out.println(actual);
12
+        Assert.assertTrue(actual == 0);
13
+
14
+    }
15
+
16
+    @Test
17
+    public void  trackTossTest(){
18
+        Bins bins = new Bins(2, 12);
19
+        Dice dice = new Dice(2);
20
+        Integer tossAndSum = dice.tossAndSum();
21
+        bins.trackTosses(tossAndSum);
22
+
23
+        Integer actual = bins.bins.get(tossAndSum);
24
+        Assert.assertTrue(actual == 1);
25
+    }
26
+}

+ 26
- 0
src/tests/java/Cherry/Akeem/DieTest.java Vedi File

@@ -0,0 +1,26 @@
1
+package Cherry.Akeem;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DieTest {
7
+
8
+    @Test
9
+    public void rollTest(){
10
+        //Given
11
+        Die die = new Die();
12
+
13
+        //When
14
+        Integer actual = die.toss();
15
+        Assert.assertTrue(actual >= 1 && actual <= 6);
16
+    }
17
+
18
+    @Test
19
+    public void rollTwentyTest(){
20
+        Die die = new Die();
21
+
22
+        Integer actual = die.toss();
23
+        Assert.assertTrue(actual >= 1 && actual <= 20);
24
+    }
25
+
26
+}