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