Class Die

java.lang.Object
  extended by Die

public class Die
extends java.lang.Object

A class representing a physical die with a default (six) or specified number of sides. Each Die object instance will have its own Random object instance to be used to generate random values when rolled. A seed value can be provided to generate repeatable behavior. A Die will always return a psuedo-random value between 1 and its number of sides, inclusive when rolled.


Field Summary
static int DEFAULT_NUMBER_OF_SIDES
           
 
Constructor Summary
Die()
          Creates a new instance of Die with six sides, initialized Random object, and the die's initial random value.
Die(int sides)
          Creates a new instance of Die with the specified number of sides, initialized Random object, and the die's initial random value.
Die(int sides, long seed)
          Creates a new instance of Die with the specified number of sides, a Random object initialized with the specified seed, and sets the die's initial random value.
Die(long seed)
          Creates a new instance of Die with the six sides, a Random object initialized with the specified seed, and sets the die's initial random value.
 
Method Summary
 int roll()
          Rolls the die by using the die's Random object to generate an integer value between 1 and the number of sides, inclusive.
 int sides()
          Returns the number of sides of the die.
 int value()
          Returns the current value of the die.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NUMBER_OF_SIDES

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

Die

public Die()
Creates a new instance of Die with six sides, initialized Random object, and the die's initial random value.


Die

public Die(int sides)
Creates a new instance of Die with the specified number of sides, initialized Random object, and the die's initial random value. constructor

Parameters:
sides - specifies the number of sides on the die

Die

public Die(long seed)
Creates a new instance of Die with the six sides, a Random object initialized with the specified seed, and sets the die's initial random value.

Parameters:
seed - specifies a seed for the random number generator.

Die

public Die(int sides,
           long seed)
Creates a new instance of Die with the specified number of sides, a Random object initialized with the specified seed, and sets the die's initial random value.

Parameters:
sides - specifies the number of sides on a die.
seed - specifies a seed for the random number generator.
Method Detail

roll

public int roll()
Rolls the die by using the die's Random object to generate an integer value between 1 and the number of sides, inclusive. The state of the die is saved so it can be retrieved more than once without re-rolling.

Returns:
the result of the roll, a value between 1 and the number of sides, inclusive.

sides

public int sides()
Returns the number of sides of the die.

Returns:
The number of sides of the die.

value

public int value()
Returns the current value of the die.

Returns:
The current value of the die.