Question
Modify the class Die to include another instance data (String), called color, to represent the color of a die. Add a getter/setter for this data.
Modify the class Die to include another instance data (String), called color, to represent the color of a die. Add a getter/setter for this data.
public class Die
{
private final intMAX = 6; // maximum face value
private intfaceValue; // current value showing on the die
//-----------------------------------------------------------------
// Constructor: Sets the initial face value.
//-----------------------------------------------------------------
public Die()
{
faceValue= 1;
}
public introll()
{
faceValue= (int)(Math.random() * MAX) + 1;
return faceValue;
}
// Face value mutator.
public void setFaceValue(intvalue)
{
faceValue= value;
}
// Face value accessor.
public intgetFaceValue()
{
return faceValue;
}
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started