diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..564671d --- /dev/null +++ b/Answers.md @@ -0,0 +1,14 @@ +# Dice Rolling Lab Answers +### John Vonelli + +*Question 1*: +The probability of rolling a 7 is 1/6. The probability of rolling a 2 is 1/36. + +*Question 2*: +I notice that the higher tallies usually fall in the single digit numbers that are greater than 5. The 100 roles is sufficent because it does show all possible roles but on a smaller scale. The 100 roles does allow the user to clearly see the relationship between the other die roles much easier than lower role counts. + +*Question 3*: +Increasing the number of simulations did not affect the results that much because the majority of the highest amount of tallies still lies between 5 and 9. + +*Question 4*: +It took 50,000 roles to get 3 significant digits for 7, and it took close to 50,000,000 rolls to get 3 significant digits for 2. Since it took less roles for the die to fall on the 7, it took much longer for the 2 to get the 3 significant digits than the 7. \ No newline at end of file diff --git a/src/Histogram.java b/src/Histogram.java new file mode 100644 index 0000000..86635bf --- /dev/null +++ b/src/Histogram.java @@ -0,0 +1,50 @@ +public class Histogram{ + private int[] gram = new int[13]; + private int count = 0; + + + public void tally(int roll){ + gram[roll] += 1; + count += 1; + } + + public int getCount(int roll){ + return gram[roll]; + } + + public double getRatio(int roll){ + return gram[roll]/(double)count; + } + + public void print(){ + int x = 2; + while(x!=13){ + System.out.println(x + ":" + " Number of Occurances: " + gram[x] + " Ratio: " + (double)gram[x]/count); + x += 1; + } + } + + public void prettyPrint(){ + int q = 2; + + while(q!=13){ + System.out.println(); + int sum = 0; + System.out.print(q + ": "); + while(sum < getCount(q)){ + System.out.print('*'); + sum += 1; + } + q += 1; + } + } + + + +} + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..7c9e710 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,29 @@ +public class Main +{ + public static void main(String[]args) + { + int total = 0; + int y = 0; + Histogram h = new Histogram(); + Die d1 = new Die(); + Die d2 = new Die(); + + while(y != 5000){ + + d1.roll(); + d2.roll(); + + //System.out.println(d1.getUpValue()); + //System.out.println(d2.getUpValue()); + + total = d1.getUpValue() + d2.getUpValue(); + //System.out.println(total); + h.tally(total); + total = 0; + y += 1; + } + h.print(); + h.prettyPrint(); + } +} +