Die Design

Instance Variables

// DrawingCanvas in which to paint Die
private DrawingCanvas canvas;

// The current roll on the die
private int currentRoll;

// Text of the current roll on the die
private Text currentRollText;

// Background of the die
private FilledRect dieBackground;

// Frame of the die
private FramedRect dieFrame;

// Random number generator between 1 and 6
private RandomIntGenerator dieValueGenerator;

 

Part A

Method Name

Parameters (types)

Description

Die

(constructor)

dieX (double)

dieY (double)

canvas (DrawingCanvas)

Randomly decide the face value of the Die (an integer between 1 and 6) and assign it to an instance variable . Construct appropriate ObjectDraw objects (and assign them to instance variables) that display the Die on the "canvas" parameter.

Part B

Method Name

Type of value returned

Parameters and (types)

Description

getX

double

none

Returns the x coordinate of the die's left edge

roll

none

none

Randomly changes the die value to a new value between 1 and 6

getRoll

int

none

Returns the current die value

Part C

Method Name

Type of value returned

Parameters (and their types)

Description

contains

boolean

Location

Returns true if the Location parameter is within the Die object on the screen; otherwise return false.

move

none

xOffset (double)

yOffset (double)

Repositions the Die object on the screen by the specified xOffset and yOffset