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
Get step-by-step solutions from verified subject matter experts
