Question: Please, I need this to be done in Java Eclipse, make sure to add comments. Thank you. Verify that the dice distribute across the potential
Please, I need this to be done in Java Eclipse, make sure to add comments. Thank you.
Verify that the dice distribute across the potential rolls evenly. The number of 1s, 2s, 3s, 4s, 5s, and 6s should be relatively the same. Since we are rolling the dice using the random generator, they usually will not be the same. So our test has to check for "outliers". Outliers are results that fall outside normal expectations. So what is a normal expectation? Well when dealing with random numbers, we are dealing with probabilities and there is a concept called a normal distribution, a bell curve.
Our testing methodology is to roll randomly and keep track of how many times a side is rolled. We can use a concept of "buckets" to contain the count. So, for example, after a roll of 2, we would increment the 2 bucket. The next roll of 4 (again random result) would increment the 4 bucket. At the end of the rolls buckets 1-6 will each have a total. The sum of the buckets must equal the number of rolls and each bucket total should be within 1 standard deviation from the mean (average)
There is a bug in the provided Die.java. You need to identify it with your tests, and fix it. Turn in the corrected Die.java
//Steps
Test the Die.java class thoroughly Create a JUnitTest named Week05JUnitTest.java with the following two tests
testMultipleDie() and testRandomDie()
testMultipleDie() will create multiple Die instances and verify the rolls are unique (that the group doesn't roll to the same value). Use the transitive property to test.
testRandomDie() will run a large number of tests (at least 1000) and check that each facet (1-6) has a value (non-zero) count, calculate the mean and standard deviation, and verify that the counts are evenly distributed within two standard deviations. Standard Deviation
Your output must be in the following format: 3 lines First line is Counts: bucket 1 total bucket 2 total bucket 3 total bucket 4 total bucket 5 total bucket 6 total Second line is Distribution: decimal per bucket Third line: mean: value, std dev: value
An example output for an unsuccessful run is:
Counts: 173 161 174 158 151 0 Distribution: 0.17 0.16 0.17 0.16 0.15 0.00 mean: 136.00, std dev: 61.43 Die failed to be randomly distributed A facet has a zero count
An example output for a successful run is: Counts: 166 175 158 169 169 163 Distribution: 0.17 0.18 0.16 0.17 0.17 0.16 mean: 166.00, std dev: 5.35
Which means the following Side one: 166 Side two: 175 Side three: 158 Side four: 169 Side five: 169 Side six: 163
The distribution is the percentage
which means Side one: 17% Side two: 18% Side three: 16% Side four: 17% Side five: 17% Side six: 16%
The mean and std deviation are as-is
The final test works like the following: Side one count: 166 is between 2 standard deviations below and 2 above. Same test for each facet
Support Info:
How to find Standard Deviation
Calculate the Mean (Links to an external site.)Links to an external site. of your data set.
For each number: subtract the Mean and square the result.
Calculate the Mean of those squared differences. The result is called the Variance (Links to an external site.)Links to an external site..
Calculate the square root of the Variance. The result is the Standard Deviation.
/*********************Die.java****************/
package week05;
import java.util.Random;
/**
* This class takes a constructor parameter to determine if it should roll or not
*
* @author Dina
*
*/
public class Die
{
/**
* Constructor
*
* @param roll
* true to roll die, otherwise initialize to NO_NUMBER;
*/
public Die(boolean roll)
{
random = new Random();
if(roll)
{
roll();
}
else
{
number = NO_NUMBER;
}
}
// Rolls the dice
public void roll()
{
number = random.nextInt(MAX_NUMBER - MIN_NUMBER + 1);
}
// Returns the number on this dice
public int getNumber()
{
return number;
}
// Data Members
// the largest number on a dice
private static final int MAX_NUMBER = 6;
// the smallest number on a dice
private static final int MIN_NUMBER = 1;
// to represent a dice that is not yet rolled
private static final int NO_NUMBER = 0;
private int number;
private Random random;
}
//**************************TestHarness******************************/
package week05;
import java.util.List;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
/**
* This class executes the JUnit Test specified from the command line
* This will be used by the reference system for testing your code.
*
* @author Dina
*
*/
public class TestHarness
{
public static void main(String[] args)
{
Result result = org.junit.runner.JUnitCore.runClasses(Week05JUnitTest.class);
int failCount = result.getFailureCount();
if( failCount > 0 )
{
List
for(Failure fail : failures)
{
trace("FAILED: " + fail.getMessage());
}
}
else
{
trace("SUCCESS");
}
}
private static void trace(String msg)
{
System.out.println(msg);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
