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

This is the submission for Tuesday's lab #4

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
14 changes: 14 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 50 additions & 0 deletions src/Histogram.java
Original file line number Diff line number Diff line change
@@ -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;
}
}



}






29 changes: 29 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}