Question: Answer needs to be in JAVA Using the Die class, design and implement a new class called PairOfDice, which uses two Die objects. Include methods

Answer needs to be in JAVA

Using the Die class, design and implement a new class called PairOfDice, which uses two Die objects. Include methods to set and get the individual die values, a method to roll the dice, and a method that returns the current sum of the two die values. Rewrite the SnakeEyes program below using a PairOfDice object.

public class ClassesNeeded { //Note: you should not need to change the Die class. public static class Die { private final int MAX = 6; private int faceValue; public Die() { faceValue = 1; } public int roll() { faceValue = (int)(Math.random() * MAX) + 1; return faceValue; } public void setFaceValue(int value) { if(value > 0 && value <= MAX) faceValue = value; } public int getFaceValue() { return faceValue; } public String toString() { String result = Integer.toString(faceValue); return result; } } public static class PairOfDice { //TODO: complete me.  } public static void main(String[] args) { final int ROLLS = 500; int count = 0; //TODO: initialize the pair of dice method   for(int roll = 1; roll <= ROLLS; roll++) { //TODO: roll the die pair and count the number of snake eyes.  // snake eyes occur when both dice roll one. } System.out.println("Number of rolls: " + ROLLS); System.out.println("Number of snake eyes: " + count); System.out.println("Ratio: " + (double)count / ROLLS); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!