forked from csci121s15/DiceRolling-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogram.java
More file actions
34 lines (24 loc) · 772 Bytes
/
Histogram.java
File metadata and controls
34 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class Histogram {
private int[] hist = new int [13];
private int total = 0;
public void tally(int roll){
hist[roll] += 1;
total += 1;
}
//increments the appropriate element of the array
public int getCount(int roll){
return hist[roll];
}
//number of occurances of the given roll
// need it to return the count so it can be used in other places
public double getRatio(int roll){
return hist[roll] / (double)total;
}
//ratio of rolls that resulted in the given total for that roll
public void print(){
for (int i = 2; i <= 12; i++){
System.out.println(i + ":" + getCount(i) + ":" + getRatio(i));
}
}
//prints a line for each possible rol1; roll value and its frequency
}