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

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!