Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago