- Objective: To create a simulation of
Die
being rolled and evaluated by aBin
which keeps track of the number of times a particular face-value has occurred. - Purpose: To establish familiarity with composition of array objects.
- This project contains 5 classes to be implemented.
Bin
- A class responsible for keeping track of the amount of times an individual face-value has occurred.Bins
- A class responsible for keeping handles manyBin
objects.Die
- A class responsible for has afaceValue
and the ability to set thefaceValue
to a random value.Dice
- A class responsible for keeping handles manyDie
objects.Simulation
- A class responsible for handlingBins
,Dice
, and computing statistical distributions.
- Within each class are several methods which must be defined to pass test cases.
- Each method has a respective Test class. For example:
new Bin()
can be tested by running thebintest.ConstructorTest
class.Bins.incrementBin(Integer)
can be tested by running thebinstest.IncrementBinTest
class.Die.roll()
can be tested by running thedietest.RollTest
class.Dice.rollAndSum()
can be tested by running thedicetest.ConstructorTest
class.Simulation.run()
can be tested by running thesimulation.RunTest
class.
- Ensure that each test-case of each test-class passes with 100% success rate.
Bin
constructor takes an argument of aInteger
representative of the die-face-value that thisBin
will be keeping track of.Bin
defines getters forfaceValueToTrack
andnumberOfOccurrences
.Bin
defines a mutatorincrement
which increments the fieldnumberOfOccurrences
by 1.- Ensure all test-cases in
bintest
pass with 100% success rate before continuing.
Bins
constructor takes an arugment of twoInteger
s representative of the minimum and maximum die-face-value to track.- Upon construction,
Bins
should create a newBin[]
and populate each element with a newBin
with a respective face-value to keep track of.
- Upon construction,
Bins
definesincrementBin
which takes an argument of anInteger
representative of theBin
containing the die-face-value whose we would like to increment the number of occurrences of.Bins
definesgetBin
which takes an argument of anInteger
representative fo theBin
containing the die-face-value we would like to retrieve.Bins
defines getter for compositeBin[]
field.- Ensure all test-cases in
binstest
pass with 100% success rate before continuing.
Die
constructor takes an argument of anInteger
representative of the number of faces thisDie
will have.Die
has anumberOfFaces
field representative of the number of faces thisDie
will have.Die
has acurrentFaceValue
field representative of the current die-face-value that is viewable.Die
definesroll
method which sets thecurrentFaceValue
field to a random value ranging between 1 and 6.Die
defines getters forcurrentFaceValue
andnumberOfFaces
- Ensure all test-cases in
dietest
pass with 100% success rate before continuing.
Dice
constructor takes an argument of anInteger
representative of the number ofDie
thisDice
will have.- Upon construction,
Dice
populates aDie[]
field with newDie
instances.
- Upon construction,
Dice
definesrollAndSum
method which returns anInteger
representative of sum of allcurrentFaceValue
on each of theDie
in theDie[]
field.Dice
definesgetRollMin
method which returns anInteger
representative of the minimum possible roll-sum.Dice
definesgetRollMax
method which returns anInteger
representative of the maximum possible roll-sum.- Ensure all test-cases in
dietest
pass with 100% success rate before continuing.
Simulation
constructor takes two arguments ofInteger
, one representative ofnumberOfDie
to be tossed, andnumberOfTimes
to toss the die.- Upon construction,
Simulation
uses each argument to set a respective field.
- Upon construction,
Simulation
defines arun
method which create a new instance ofDice
with respectivenumberOfDie
passed as an argument upon construction.run
creates new instance ofBins
usingrollMinimum
androllMaximum
as its constructor arguments.run
invokesroll
ondice
fornumberOfTimes
number of times.
Simulation
defines agetPercentageOfOccurrences
method which takes an argument of anInteger
representative of the die-face-value to evaluate, and returns aDouble
representative of the percentage of times the face-value has occurred.- Ensure all test-cases in
simulationtest
pass with 100% success rate before continuing.
-
Use
MainApplication.main(String[])
to run simulations. -
Create readable output to display distributions of occurrences by
@Override
ing thetoString()
method inSimulation
. -
Sample Script
Simulation simulation = new Simulation(2, 1000000);
simulation.run();
String results = simulation.toString();
System.out.println(results);
- Sample Script Output
***
SimulationTest of 2 dice tossed for 1000000 times.
***
2 : 27917: 0.03 **
3 : 55422: 0.06 *****
4 : 83457: 0.08 ********
5 : 110961: 0.11 ***********
6 : 139098: 0.14 *************
7 : 166977: 0.17 ****************
8 : 138386: 0.14 *************
9 : 111102: 0.11 ***********
10 : 83367: 0.08 ********
11 : 55799: 0.06 *****
12 : 27514: 0.03 **