Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turning in DiceRolling-Lab. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Probability of rolling a seven is 1 / 6. Probability of rolling a 2 is 1 / 36.

2. The bulk of the values is around the middle numbers such as 5 through 9. 100 rolls is not efficient to determine the frequency.

3. The highest frequency of values are still 5 through 9 but they seem to overall be closer.

4. At 500,000 rolls you can accurately predict the probability of rolling a 7 to 3 significant digits. At 300,00 rolls you can accurately predict the probability of rolling a 2 to 3 significant digits.
26 changes: 26 additions & 0 deletions src/Histogram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Histogram {
private int[] data = new int[13];
private int count = 0;

public void tally(int roll) {
data[roll] += 1;
count += 1;
}

public int getCount(int roll) {
return data[roll];
}

public double getRatio(int roll) {
return data[roll] / (double) count;
}

public void print() {
int val = 2;
while (val <= 12) {
System.out.println(val +"/" + data[val] + "*" + getRatio(val));

val += 1;
}
}
}
22 changes: 22 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Main {
public static void main(String[] args) {

int total = 0;

Histogram h = new Histogram();

Die d1 = new Die();
Die d2 = new Die();

for(int i = 0; i < 300000; i++) {
d1.roll();
d2.roll();
total = d1.getUpValue() + d2.getUpValue();
h.tally(total);
}
h.print();
}
}