Java Programming I on YouTube:
https://www.youtube.com/playlist?list=PLLIqcoGpl73iaXAtS_-V_Xdx3mhTzPwb5
For the roll of a single die, all outcomes are equally probable. However, in the roll of two dice, the probabilities are different for the sum of two dice. In fact, some combinations are more probable because there are more ways to roll certain numbers than the others.
For example, for traditional 6-sided dice, there are six ways to get a sum of 7, but only one combination to get 2. Therefore, the odds of getting a 7 are six times higher than the possibility of rolling the "snake eyes".
In this project we develop a program to roll a series of dice pairs and calculate statistics about the dice combinations in a series of rolls.
The program greets the user
Welcome to the Dice Roll Stats Calculator!
and asks how many times to roll the pair of dice:
How many times to roll the dice? (zero to exit)
There are two Java classes in this application: DiceRoller and Indicator. Also, the Validator class handles the user interaction.
There are two private arrays in the DiceRoller class. The first is an array of ints capturing results of a series of dice rolls:
private int[] rollSeries;
The second array stores statistical Indicators to accumulate the data about the series of rolls:
private Indicator[] statIndicators;
For a traditional 6-sided dice, the size of statIndicators
array should be 13,
because this is how much space we need to hold all possible combinations between
1 + 1 = 2
and
6 + 6 = 12
The constructor of DiceRoller class "rolls" the dice the number of times requested by the user. DiceRoller also has methods to collect statistics and print the statistical report.
The Indicator class holds two values: dicePairTotal
and dicePairCount
:
public class Indicator implements Comparable<Indicator> { private final int dicePairTotal; private int dicePairCount; //...
Because we roll a pair of cube dice, the values rolled, dicePairTotal
,
can be one of the following:
1+1, 1+2, ..., 1+6, 2+1, 2+2, ..., 2+6, 3+1, 3+2, ..., 3+6, ... 6+1, 6+2, ..., 6+6
In the statIndicators
array of the DiceRoller we have one Indicator
with unique dicePairTotal
from a set of all possible combinations 2, 3, 4, ..., 12.
The second variable in the Indicator class, dicePairTotal
, keeps the score how many times
each dicePairTotal
combination has rolled in the current the series of the rolls.
The main()
method provides a loop for continuous rolls and exists when
the number of rolls entered by the user is zero.
Watch instructional video for a complete overview of this assignment.
We need to sort the statIndicators
array in the DiceRoller class before displaying the stats.
For this reason, Indicator objects are made sortable by dicePairCount
,
which is done via implementing the Comparable interface.
For example, if a user rolls a pair of 6-sided dice 10 times, the output might be
----------------------- dice pair roll total count percent ---- ------ -------- 7 5 50% 10 2 20% 4 2 20% 2 1 10%
The prototype program does not exclude combinations of dice totals with zero roll counts from the printout. You need to add some filtering code to hide the combinations that never rolled.
The prototype does not have a descriptive report header, either. You need to add a header to your report.
Finally, add the code to calculate and print the percent of the roll counts within the entire series of rolls.
Before submitting, ZIP your src folder containing all Java source files and submit it as a single ZIP archive.
PLEASE DO NOT send any NetBeans projects or compiled .class files. I only need your Java source code to grade this assignment.