diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..ee7f243 --- /dev/null +++ b/Answers.md @@ -0,0 +1,18 @@ +#John Ferguson 2/5/15 +##Dice Rolling Lab + +>**Question 1:** The probability of rolling a certain number is the number of possbile rolls that can sum to that number divided by the total number of possible rolls. What is the probability of rolling a 7? What is the probability of rolling a 2? + +**Answer 1:** The probability of rolling a 7 is a 1/6 chance. The chance of rolling a 2 is a 1/18 chance. + +>**Question 2:** Comment on the variation of values among the simulation runs. Is 100 rolls sufficient to determine the relative frequency of all the possible rolls? + +**Answer 2:** Everytime we ran our simulation the numbers changed because it was at random. Since it was random I didn't see any consistency. Therefore, I don't believe 100 rolls is sufficient to determine the relative frequency of all the rolls. + +>**Quesiton 3:** How did increasing the number of simulations affect the results? + +**Answer 3:** Increasing the number of simulations gives us more sufficient results. The results were much close to being consistent for example, for 2 the range was anywhere from .24 to .34 in the ratio which is pretty close. + +>**Question 4:** How many rolls per simulation does it take before you can accuarately predict the probability of rolling 7 to 3 significant digits five times in a row? How about for the probability of rolling a 2? + +**Answer 4:** The amount of rolls per simulation it takes to accurately predict the probablility of rolling a 7 is about 1000 rolls to get if five times in a row. To roll a 2, its about 5000 rolls to get it five times in a row. diff --git a/src/Histogram.java b/src/Histogram.java new file mode 100644 index 0000000..5bd0185 --- /dev/null +++ b/src/Histogram.java @@ -0,0 +1,25 @@ +public class Histogram { + private int[] hist = new int [13]; + private int totalRolls = 0; + + public void tally(int roll) { + hist[roll] += 1; + totalRolls += 1; + } + + public int getCount(int roll) { + + return hist[roll]; + } + + public double getRatio(int roll) { + + return hist[roll] / (double)totalRolls; + } + + public void print() { + for (int i= 2; i <= 12; i++) { + System.out.println(i + ": " + getCount(i) + " " + getRatio(i)); + } +} +} diff --git a/src/SimulationRunner.java b/src/SimulationRunner.java new file mode 100644 index 0000000..db56616 --- /dev/null +++ b/src/SimulationRunner.java @@ -0,0 +1,17 @@ +public class SimulationRunner { + public static void main(String[] args) { + Die d1 = new Die(); + Die d2 = new Die(); + + Histogram hist = new Histogram(); + + for (int count = 0; count < 5000; count++) { + d1.roll(); + d2.roll(); + + hist.tally(d1.getUpValue() + d2.getUpValue()); + } + + hist.print(); + } +} \ No newline at end of file