Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions