Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the class Die presented in class to include another instance data (String), called color, to represent the color of a die. Add a getter/setter

Modify the class Die presented in class to include another instance data (String), called color, to represent the color of a die.

Add a getter/setter for this data and modify the toString method to return color as well.

Modify the driver program to create 2 dice (one red, one blue) with random face values.

The program should display the dice information as well as create another die with color to be the combination of the two dice colors (eg. red_and_blue) and face value to be the integer average of the faces of the two dice.

die.java

import java.util.Scanner; public class Die { private int faceValue; public Die() { faceValue=(int)(Math.random()*6)+1; roll(); } public Die(int value) { faceValue=value; } public int getFaceValue() { return faceValue; } public void setFaceValue(int value) { faceValue=value; } public void roll() { faceValue=(int)(Math.random()*6)+1; } public String toString() { return "Die with face: "+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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago