Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!