#35 Elliott Dicey

Открыто
ElliottStansbury хочет смерджить 1 коммит(ов) из ElliottStansbury/ZCW-DiceyLab:master в master
4 измененных файлов: 126 добавлений и 1 удалений
  1. 33
    0
      src/main/java/Bins.java
  2. 74
    1
      src/main/java/Dice.java
  3. 4
    0
      src/main/java/Simulation.java
  4. 15
    0
      src/main/java/main.java

+ 33
- 0
src/main/java/Bins.java Просмотреть файл

@@ -1,4 +1,37 @@
1
+import java.util.Arrays;
1 2
 
2 3
 public class Bins {
4
+   // public int add()
5
+
6
+    int[] result;
7
+    int amountOfDie;
8
+    int numberOfSides;
9
+    int[] test;
10
+
11
+
12
+
13
+    public Bins(int amountOfDie, int numberOfSides){
14
+     this.amountOfDie = amountOfDie;
15
+     this.numberOfSides = numberOfSides;
16
+     this.result = new int[(amountOfDie * numberOfSides) - (amountOfDie - 1)];
17
+     this.test = new int[result.length];
18
+
19
+     int counter = 0;
20
+     for(int i =amountOfDie; i <= result.length+ 1; i++){
21
+         test[counter] = i ;
22
+
23
+         //if(i < numberOfSides*amountOfDie + amountOfDie -2) {
24
+             counter++;
25
+         //}
26
+     }
27
+    }
28
+
29
+    public void addResult(int sum){
30
+        result[sum- amountOfDie]++;
31
+        System.out.println(Arrays.toString(result));
32
+        System.out.println(Arrays.toString(test));
33
+    }
34
+
3 35
 
4 36
 }
37
+

+ 74
- 1
src/main/java/Dice.java Просмотреть файл

@@ -1,4 +1,77 @@
1
+import java.util.Random;
2
+
1 3
 public class Dice {
2 4
 
5
+  //  public static void main(String[] args) {
6
+
7
+//        Random rand = new Random();
8
+//        int freq[] = new int[13];
9
+//
10
+//        for(int roll = 2; roll < 10000000; roll++){
11
+//            ++freq[1+rand.nextInt(12)];
12
+//        }
13
+//
14
+//        System.out.println("Face\tFrquency");
15
+//
16
+//        for(int face=2; face < freq.length;face++){
17
+//            System.out.println(face+"\t"+"\t"+freq[face]);
18
+//        }
19
+
20
+        public Random random;
21
+        private int sides;
22
+        private int amountOfDie;
23
+
24
+//        public void dice(int numOfSides){
25
+//            this.sides = numOfSides;
26
+//        }
27
+
28
+        public Dice(int sides, int amountOfDie) {
29
+            this.sides = sides;
30
+            random = new Random();
31
+            this.amountOfDie = amountOfDie;
32
+        }
33
+
34
+        // Rolling dice a million times
35
+//        Dice dice1 = new Dice(6,  3);
36
+//        Dice dice2 = new Dice(6, 2);
37
+
38
+
39
+
40
+
41
+
42
+    public void rollDice(int numberOfRolls) {
43
+
44
+            int totals[] = new int[sides*sides]; //frequencies of the sums
45
+
46
+
47
+            //initialize totals to zero
48
+            for (int i = 0; i < totals.length; i++) {
49
+                totals[i] = 0;
50
+            }
51
+
52
+            //roll the dice
53
+            for (int roll = 1; roll <= numberOfRolls; roll++) {
54
+                int sum = 0;
55
+               for(int dice = 0; dice < amountOfDie; dice++){
56
+                   int valueOfRoll = (int)(Math.floor(Math.random() * sides) + 1);
57
+                    sum += valueOfRoll;
58
+               }
59
+                totals[roll] += sum;
60
+            }
61
+
62
+            //print out the table
63
+            System.out.println( "Sum\tFrequency\tPercentage");
64
+
65
+            //ignore subscripts 0 & 1
66
+            for (int j = 2; j < totals.length; j++) {
67
+                double percent = (((double) totals[j] / (1000000)));
68
+                int reformPercent = (int) (Math.ceil(percent * 100));
69
+                System.out.printf("%3d%12d%12d\n", j, totals[j], reformPercent);
70
+            }//end for
71
+        }//end method
72
+
73
+
74
+    }//end class
75
+
76
+
3 77
 
4
-}

+ 4
- 0
src/main/java/Simulation.java Просмотреть файл

@@ -1,5 +1,9 @@
1 1
 public class Simulation {
2 2
 
3
+private int numberOfSides;
4
+private int amountOfDie;
5
+//
3 6
 
4 7
 
8
+    //public
5 9
 }

+ 15
- 0
src/main/java/main.java Просмотреть файл

@@ -0,0 +1,15 @@
1
+public class main {
2
+
3
+    public static void main(String[] args){
4
+        Dice dice = new Dice(6,2);
5
+        Bins bins = new Bins(4,6);
6
+
7
+       dice.rollDice(3);
8
+      //  bins.addResult(3);
9
+       // bins.addResult(5);
10
+
11
+//dice.rollDice(5);
12
+
13
+    }
14
+
15
+}