Class RollingDie

java.lang.Object
  extended by RollingDie

public class RollingDie
extends java.lang.Object

RollingDie class Instantiable class whose instances model playing dice; rolling a die results in a pseudorandom int between 1 and the number of sides being assigned as the face value; RollingDie instances have 6 sides by default; a different number of sides may also be specified. Sergio A. Alvarez, Oct. 2005.


Field Summary
static int DEFAULT_NUM_SIDES
           
 
Constructor Summary
RollingDie()
          default constructor, constructs a 6-sided die.
RollingDie(int numSides)
          constructs a die with a specified number of sides.
 
Method Summary
 int getFace()
          returns the face currently showing on this die; does not roll die.
 javax.swing.ImageIcon getIcon()
          returns an image of the face currently showing on this die.
 int roll()
          pseudorandomly assigns a face value between 1 and the number of sides; returns the resulting face value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NUM_SIDES

public static final int DEFAULT_NUM_SIDES
See Also:
Constant Field Values
Constructor Detail

RollingDie

public RollingDie(int numSides)
constructs a die with a specified number of sides.

Parameters:
numSides - the desired number of sides of this instance

RollingDie

public RollingDie()
default constructor, constructs a 6-sided die.

Method Detail

roll

public int roll()
pseudorandomly assigns a face value between 1 and the number of sides; returns the resulting face value.

Returns:
the face showing on this die after rolling

getFace

public int getFace()
returns the face currently showing on this die; does not roll die.

Returns:
the face currently showing on this die

getIcon

public javax.swing.ImageIcon getIcon()
returns an image of the face currently showing on this die.

Returns:
an ImageIcon showing the current face on this die