Bläddra i källkod

Merge 0ba3b812e56c7c41d667c172417f59d243df6f20 into 1eaff706f0dcc7a467d1c6648bcb494e313ba6a5

amygdal 6 år sedan
förälder
incheckning
c6ad133b37
No account linked to committer's email

+ 10
- 0
pom.xml Visa fil

@@ -8,5 +8,15 @@
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+
13
+        <dependency>
14
+            <groupId>junit</groupId>
15
+            <artifactId>junit</artifactId>
16
+            <version>RELEASE</version>
17
+        </dependency>
18
+
19
+    </dependencies>
20
+
11 21
 
12 22
 </project>

+ 17
- 0
src/main/java/Bins.java Visa fil

@@ -1,4 +1,21 @@
1
+import java.util.HashMap;
1 2
 
2 3
 public class Bins {
3 4
 
5
+    protected HashMap<Integer, Integer> numOfTimesWeveRolledEachNUm = new HashMap<Integer, Integer>();
6
+
7
+    public Bins(Integer smallestPossible, Integer largestPossible){
8
+        for (Integer key = smallestPossible; key <= largestPossible; key++){
9
+            numOfTimesWeveRolledEachNUm.put(key, 0);
10
+        }
11
+    }
12
+
13
+    public Bins(int start, int end) {
14
+
15
+
16
+    }
17
+
18
+    public Integer getBin(int numToCheck) {
19
+        return null;
20
+    }
4 21
 }

+ 49
- 0
src/main/java/Dice.java Visa fil

@@ -1,4 +1,53 @@
1 1
 public class Dice {
2 2
 
3
+    private int numOfDice;
4
+    private int minNum;
5
+    private int maxNum;
3 6
 
7
+
8
+    public Dice(){
9
+        this(1);
10
+    }
11
+
12
+    public Dice(int numOfDice){
13
+        this.numOfDice = numOfDice;
14
+        this.minNum= numOfDice;
15
+        this.maxNum = numOfDice * 6;
16
+    }
17
+
18
+    public int getMinNum() {
19
+        return minNum;
20
+    }
21
+
22
+    public int getMaxNum() {
23
+        return maxNum;
24
+    }
25
+
26
+    public int tossAndSum(){
27
+        int rollSum = 0;
28
+        for (int i = 0; i <numOfDice; i++){
29
+            rollSum += (int) (Math.random() *6) + 1;
30
+        }
31
+
32
+        return rollSum;
33
+
34
+    }
35
+
36
+    public static void main(String[] args) {
37
+        Dice dice = new Dice(2); // for craps
38
+        Dice dice2 = new Dice(5); // for yatzee
39
+
40
+        Integer toss = dice.tossAndSum();
41
+        Integer toss2 = dice2.tossAndSum();
42
+
43
+        System.out.println("The result of the first toss was " + toss);
44
+        System.out.println("The result of the second toss was " + toss2);
45
+
46
+
47
+
48
+    }
49
+
50
+//    public int rollDice(int numDice) {
51
+//        return (int) (Math.random()*numDice*6);
52
+//    }
4 53
 }

+ 2
- 1
src/main/java/Simulation.java Visa fil

@@ -1,5 +1,6 @@
1 1
 public class Simulation {
2 2
 
3 3
 
4
-
4
+    public Simulation(int numDice, int numTosses) {
5
+    }
5 6
 }

+ 29
- 0
src/test/java/BinsTest.java Visa fil

@@ -0,0 +1,29 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+public class BinsTest {
5
+    @Test
6
+    public void binsTest() {
7
+        Bins results = new Bins(2,12);
8
+
9
+        int expected = -1;
10
+        int actual = -2;
11
+
12
+        Assert.assertEquals(expected,actual);
13
+
14
+    }
15
+
16
+    @Test
17
+    public void numOfTensTest(){
18
+        Bins results = new Bins(2,12);
19
+        Integer numberOfTens = results.getBin(10);
20
+    }
21
+
22
+//    @Test
23
+//    public void incrementBinsTest(){
24
+//        Bins results;
25
+//        results.incrementBin(10);
26
+//    }
27
+
28
+
29
+}

+ 19
- 0
src/test/java/DiceTest.java Visa fil

@@ -0,0 +1,19 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
4
+//public class DiceTest {
5
+//    @Test
6
+//    public void rollTest() {
7
+//        //Given
8
+//            //a Dice Object and supply number of dice
9
+//            Dice testDice = new Dice(2);
10
+//        //When
11
+//            //I roll it/them
12
+////        testDice.rollDice(2);
13
+////        //Then
14
+////            //I want it to give me a random number
15
+////        int actual = testDice.rollDice(2);
16
+////
17
+////        Assert.assertTrue(actual >=12);
18
+////    }
19
+////}

+ 3
- 0
src/test/java/SimulationTest.java Visa fil

@@ -0,0 +1,3 @@
1
+public class SimulationTest {
2
+    Simulation sim = new Simulation(2, 10000);
3
+}