Question
PLEASE USE JAVA Given Die class (Die.java), write a program that instantiates two Die objects and rolls them repeatedly until they are equal (use equals()
PLEASE USE JAVA
Given Die class (Die.java), write a program that instantiates two Die objects and rolls them repeatedly until they are "equal" (use equals() or compareTo() method). The program prints the number of times both dice landed on an odd number.
DIE CLASS:
public class Die { //attributes private int faceValue; //operations //default constructor public Die(){ //faceValue = 2; roll(); } //non-default constructor public Die(int face) { faceValue = face; } //roll method public void roll() { faceValue = (int)(Math.random() * 6) + 1; } //getter public int getFaceValue() { return faceValue; } //setter public void setFaceValue(int face){ faceValue = face; } //compareTo public int compareTo(Die die){ if(faceValue>die.getFaceValue()){ return 1; } else if (faceValue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started