|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectDie
public class Die
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 |
|---|
public static final int DEFAULT_NUMBER_OF_SIDES
| Constructor Detail |
|---|
public Die()
public Die(int sides)
sides - specifies the number of sides on the diepublic Die(long seed)
seed - specifies a seed for the random number generator.
public Die(int sides,
long seed)
sides - specifies the number of sides on a die.seed - specifies a seed for the random number generator.| Method Detail |
|---|
public int roll()
public int sides()
public int value()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||