Answer :
Answer:
Program Dice.java
=================================================
import java.util.Random;
public class Dice
{
private int spots; //the number of spots up on the die
private static Random generator;
//a random number generator use simulating rolling dice,
//shared by all dice, so that it will be as random as possible
//constructor creates a single die, inititally with no spots
public Dice()
{
//create an instance of the random
generator = new Random();
spots = 0;
}
//simulates rolling the die and stores the numbers rolled
public void roll()
{
//return 1,2,3,4,5, or 6
spots = generator.nextInt(6) + 1;
}
//return the value of the die
public int getSpots()
{
return spots;
}
}
=========================================================
Program DiceSimulation.java
=========================================================
public class DiceSimulation
{
public static void main(String [] args)
{
final int NUMBER = 10000; //the number of times the roll the dice
Dice die1 = new Dice(); //first die
Dice die2 = new Dice(); //second die
int die1Value; //the number of spots on the second die
int die2Value; //the number of spots on the first die
int count = 0; //number of times the dice were rolled
int snakeEye = 0; //number of times of snakes eyes is rolled
//number of times double two's, three's, four's, five's, six's
int twos = 0;
int threes = 0;
int fours = 0;
int fives = 0;
int sixes = 0;
//ENTER YOUR CODE FOR THE ALGORITHM HERE
for(count=0;count<=NUMBER;count++)
{
die1.roll();
int t1=die1.getSpots();
die2.roll();
int t2=die2.getSpots();
if(t1==t2)
{
if(t1==1)snakeEye++;
else if(t1==2)twos++;
else if(t1==3)threes++;
else if(t1==4)fours++;
else if(t1==5)fives++;
else if(t1==6)sixes++;
}
}
count--;
//output to console
System.out.println("You rolled snake eyes " + snakeEye
+ " out of " + count + " rolls.");
System.out.println("You rolled double two " + twos
+ " out of " + count + " rolls.");
System.out.println("You rolled double threes " + threes
+ " out of " + count + " rolls.");
System.out.println("You rolled double fours " + fours
+ " out of " + count + " rolls.");
System.out.println("You rolled double fives " + fives
+ " out of " + count + " rolls.");
System.out.println("You rolled double sixes " + sixes
+ " out of " + count + " rolls.");
}
}
========================================================
Sample output:
