Browse Source

it is what it is

Jarrett Samuels 6 years ago
parent
commit
5db9c1418c
6 changed files with 141 additions and 3 deletions
  1. 1
    1
      README.md
  2. 12
    0
      pom.xml
  3. 8
    1
      src/main/java/Bins.java
  4. 24
    0
      src/main/java/Console.java
  5. 25
    0
      src/main/java/Dice.java
  6. 71
    1
      src/main/java/Simulation.java

+ 1
- 1
README.md View File

@@ -12,7 +12,7 @@ make a couple unit tests for the Dice class.
12 12
 Create a tracking class `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
+Bins results = new 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
 

+ 12
- 0
pom.xml View File

@@ -8,5 +8,17 @@
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <build>
12
+        <plugins>
13
+            <plugin>
14
+                <groupId>org.apache.maven.plugins</groupId>
15
+                <artifactId>maven-compiler-plugin</artifactId>
16
+                <configuration>
17
+                    <source>1.8</source>
18
+                    <target>1.8</target>
19
+                </configuration>
20
+            </plugin>
21
+        </plugins>
22
+    </build>
11 23
 
12 24
 </project>

+ 8
- 1
src/main/java/Bins.java View File

@@ -1,4 +1,11 @@
1
+import java.util.HashMap;
1 2
 
2 3
 public class Bins {
3 4
 
4
-}
5
+    public Bins (HashMap<Integer, Integer> storage) {
6
+
7
+    }
8
+
9
+    // Games will be stored in multiple bin objects
10
+
11
+    }

+ 24
- 0
src/main/java/Console.java View File

@@ -0,0 +1,24 @@
1
+import java.util.*;
2
+
3
+public class Console {
4
+
5
+    public static void main(String[] args) {
6
+
7
+        Scanner console = new Scanner(System.in);
8
+
9
+        System.out.println("Enter Number of Die");
10
+
11
+        int numOfDie = console.nextInt();
12
+
13
+        System.out.println("Now please enter number of tosses");
14
+
15
+        int numOfTosses = console.nextInt();
16
+
17
+        Dice die = new Dice(numOfDie, numOfTosses);
18
+
19
+
20
+        // return lowest possible score (int lowestScore)
21
+        // and highest possible score (int highestScore)
22
+
23
+    }
24
+}

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

@@ -1,4 +1,29 @@
1
+import java.util.*;
2
+
3
+
1 4
 public class Dice {
2 5
 
6
+    public Dice (int numOfDie, int numOfTosses){
7
+
8
+        Scanner console = new Scanner(System.in);
9
+
10
+        int maxOutcome = numOfDie * 6;
11
+
12
+        System.out.println("Maximum outcome has now been calculated! Would you like to run the simulation? (#1 for yes #2 for no)");
13
+
14
+        int choice = console.nextInt();
15
+
16
+        if (choice == 1) {
17
+
18
+            Simulation Sim = new Simulation(numOfDie, maxOutcome, numOfTosses);
19
+
20
+        } else {
21
+
22
+        System.out.println("Bye!");
23
+
24
+        console.close();
25
+
26
+        }
3 27
 
28
+    }
4 29
 }

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

@@ -1,5 +1,75 @@
1
+import java.text.DecimalFormat;
2
+import java.util.*;
3
+import java.util.concurrent.ThreadLocalRandom;
4
+
1 5
 public class Simulation {
2 6
 
7
+    public Simulation (int min, int max, int tosses) {
8
+
9
+        int binCounter = 0;
10
+        int tossCounter = min;
11
+        int mapCounter = min;
12
+
13
+        HashMap<Integer, Integer> map = new HashMap<>();
14
+
15
+        // building HashMap for results
16
+
17
+        while (mapCounter <= max) {
18
+            map.put(mapCounter, 0);
19
+            mapCounter++;
20
+        }
21
+
22
+        // Running Simulation
23
+
24
+        for (int i = 1; i <= tosses; i++) {
25
+            int result = ThreadLocalRandom.current().nextInt(min, max);
26
+            int increment = map.get(result);
27
+            map.put(result, increment + 1);
28
+        }
29
+
30
+        /* while (tossCounter < tosses) {
31
+
32
+            int result = ThreadLocalRandom.current().nextInt(min, max);
33
+            map.put(tossCounter, result);
34
+
35
+        tossCounter++; */
36
+
37
+        Bins localstorage = new Bins(map);
38
+
39
+        //printing results
40
+        System.out.print(map + System.getProperty("line.separator"));
41
+
42
+            int counter = min;
43
+            String output = "";
44
+
45
+                for (int y = min; y <= max; y++) {
46
+
47
+                    // calculate percentage
48
+
49
+
50
+                    int getTosses = map.get(y);
51
+                    double percentage = (double)getTosses/max;
52
+                    DecimalFormat df = new DecimalFormat("#0.00");
53
+                    String percent = df.format(percentage);
54
+                    double convert = Double.parseDouble(percent);
55
+
56
+                    // calculate stars
57
+
58
+                    double z = 0.01;
59
+                    String stars = "";
60
+
61
+                    while (z < convert) {
62
+                        stars += "*";
63
+                        z = z + 0.01;
64
+                    }
65
+
66
+                    // print each line
67
+
68
+                    output += String.format("%3d", y) + " :" + String.format("%9d", getTosses) + ": " + String.format("%.2f", convert) + " " + stars + System.getProperty("line.separator");
69
+                }
70
+
71
+        System.out.println(output);
3 72
 
73
+        }
4 74
 
5
-}
75
+    }