Browse Source

Dices Dices

Whitney Martinez 6 years ago
parent
commit
efc781e64e

+ 13
- 0
WhitneysFile.md View File

@@ -0,0 +1,13 @@
1
+Rolls amount,    Roll times,      perc 
2
+          2 ~           530 ~       0.05 ~ *****      
3
+         3 ~          1132 ~       0.11 ~ *********** 
4
+         4 ~          1634 ~       0.16 ~ **************** 
5
+         5 ~          2273 ~       0.23 ~ *********************** 
6
+         6 ~          2856 ~       0.29 ~ ***************************** 
7
+         7 ~          3280 ~       0.33 ~ ********************************* 
8
+         8 ~          2751 ~       0.28 ~ **************************** 
9
+         9 ~          2169 ~       0.22 ~ ********************** 
10
+        10 ~          1659 ~       0.17 ~ ***************** 
11
+        11 ~          1123 ~       0.11 ~ *********** 
12
+        12 ~           593 ~       0.06 ~ ******     
13
+

+ 20
- 0
pom.xml View File

@@ -7,6 +7,26 @@
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>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>org.junit.jupiter</groupId>
25
+            <artifactId>junit-jupiter-api</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>compile</scope>
28
+        </dependency>
29
+    </dependencies>
10 30
 
11 31
 
12 32
 </project>

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

@@ -1,4 +1,62 @@
1
+import java.util.ArrayList;
2
+import java.util.HashMap;
1 3
 
2 4
 public class Bins {
3 5
 
6
+      //private Dice die = new Dice(2);
7
+
8
+
9
+      protected HashMap<Integer,Integer> binbin;
10
+
11
+
12
+
13
+
14
+      public Bins (int min, int max) {
15
+
16
+            binbin = new HashMap<Integer, Integer>();
17
+           BinofholdingCalculations(min,max);
18
+
19
+
20
+      }
21
+
22
+
23
+
24
+      public void BinofholdingCalculations (int min,int max){
25
+            //number of die and num of rolls then minus the num of die plus 1
26
+            // for the size of the array..
27
+
28
+
29
+          for(int i = min; i <=max; i++){
30
+
31
+              binbin.put(i, 0);
32
+
33
+          }
34
+      }
35
+      public void seetosses(int sum){
36
+
37
+          binbin.put(sum, binbin.get(sum)+1);
38
+
39
+      }
40
+
41
+
4 42
 }
43
+
44
+
45
+//        public ArrayList<Integer>Loggingthesebins(int numberofdice) {
46
+//            ArrayList<Integer> log = new ArrayList<>();
47
+//
48
+//            int lengthofthearray = (numberofdice * 6) - (numberofdice - 1);
49
+//
50
+//            binbin.add(numberofdice);
51
+//
52
+//
53
+//            for (int j = 0; j < lengthofthearray; j++) {
54
+//
55
+//                log.add(0);
56
+//
57
+//            }
58
+//            return log;
59
+//      }
60
+
61
+
62
+

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

@@ -1,4 +1,26 @@
1
+import java.util.Random;
2
+
1 3
 public class Dice {
2 4
 
5
+    private int dice;
6
+
7
+        public Dice(int dice){
8
+
9
+            this.dice = dice;
10
+
11
+        }
12
+        public int letsroll(){
13
+            Random r=  new Random();
14
+            int rolltimes =0;
15
+
16
+            for(int i = 0; i < dice; i++){
17
+
18
+                rolltimes += (r.nextInt(6)+1);
19
+
20
+                System.out.println("You've rolled "+ rolltimes);
21
+
22
+            }
23
+            return rolltimes;
3 24
 
25
+        }
4 26
 }

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

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

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

@@ -1,5 +1,86 @@
1
+import java.util.ArrayList;
2
+import java.util.Formatter;
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
1 6
 public class Simulation {
7
+//my fields
8
+    private int numdice;
9
+    private int numthrows;
10
+    private Dice throwz;
11
+    private Bins Binsh;
12
+    HashMap<Integer,Integer>binlis;
13
+
14
+
15
+    public Simulation(int di, int thr)
16
+    {
17
+        this.throwz = new Dice(di);
18
+        this.Binsh = new Bins(di, di*6);
19
+        this.numdice=di;
20
+        this.numthrows=thr;
21
+        binlis = Binsh.binbin;
22
+
23
+    }
24
+// the constructors
25
+    public int getlast(){
26
+
27
+        int total =throwz.letsroll();
28
+        return total;
29
+    }
30
+
31
+
32
+    public void runSimulation(){
33
+        for(int i = 0; i < numthrows; i++){
34
+
35
+            Binsh.seetosses(getlast());
36
+            }
37
+        }
38
+    public double perc(int key){
39
+
40
+        double percent = (double) binlis.get(key)/numthrows;
41
+        return percent;
42
+        }
43
+
44
+    public String stars(double value){
45
+
46
+        String sta = "";
47
+        int starnumbets = (int)Math.round(value *100);
48
+        for (int i = 1; i <=starnumbets; i++){
49
+
50
+            sta +="*";
51
+
52
+        }
53
+        return sta;
54
+    }
55
+    public double totalxperc(){
56
+
57
+        double total =0;
58
+
59
+        for(Integer key : binlis.keySet()) {
60
+            total = total + perc(key);
61
+        }
62
+        return total;
63
+        }
64
+
65
+
66
+
67
+    public Bins printResults() {
68
+        return this.Binsh;
69
+
70
+    }
71
+    public void print() {
72
+        runSimulation();
73
+        StringBuilder result = new StringBuilder();
74
+        Formatter format = new Formatter(result);
75
+
76
+        result.append("***Heres this dicey Simulation" + numdice + "dice tossed %,7d times\n***\n\n" + numthrows + " these many times!****\n \t");
77
+
78
+        System.out.printf("%10s, %13s,%10s \n ","Rolls amount","Roll times","perc","vol");
2 79
 
80
+        for(Integer key : Binsh.binbin.keySet()){
3 81
 
82
+            System.out.printf("%10d ~ %13d ~ %10.2f ~ %-10s \n",key,Binsh.binbin.get(key),perc(key),stars(perc(key)));
83
+        }
4 84
 
5
-}
85
+    }
86
+}

+ 37
- 0
src/main/java/TestDie.java View File

@@ -0,0 +1,37 @@
1
+import com.sun.tools.javac.util.Assert;
2
+import org.junit.jupiter.api.Test;
3
+
4
+import java.util.ArrayList;
5
+
6
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
7
+import static org.junit.jupiter.api.Assertions.assertTrue;
8
+
9
+public class TestDie {
10
+
11
+
12
+
13
+    @Test
14
+    public void TestingDice1() {
15
+
16
+        Dice die = new Dice(1);
17
+
18
+        boolean actual = false;
19
+        int dies = die.letsroll();
20
+        if (dies <= 6 && dies >= 1) {
21
+
22
+
23
+        }
24
+        assertTrue(actual);
25
+    }
26
+        @Test
27
+        public void testdice2() {
28
+        Dice die = new Dice(3);
29
+        int actual = die.letsroll();
30
+
31
+        assertTrue(actual >= 3 && actual <= 18);
32
+
33
+
34
+        }
35
+
36
+
37
+}

+ 5
- 0
src/main/java/TestMain.java View File

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