Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

What are Fatty acids?

Answered: 1 week ago

Question

What are Electrophoresis?

Answered: 1 week ago