public class Die extends Object implements Comparable<Die>
1
in increments of 1
for
each additional face.Constructor and Description |
---|
Die()
Create a six sided die and sets its face value to a random
value between
1 and 6 , inclusive. |
Die(Die d)
Create a die that has the same number of faces and same value
as another die.
|
Die(int faces)
Create a die with the specified number of faces and sets its
face value to a random value between
1 and
faces , inclusive. |
Die(int faces,
int value)
Create a die with the specified number of faces and sets its
face value to a specified value.
|
Die(int faces,
Random rng)
Create a die with the specified number of faces and a specified
random number generator, and sets its face value to a random
value between
1 and faces , inclusive. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Die other)
Compares two dice by their face value.
|
boolean |
equals(Object obj)
Compares two dice for equality.
|
int |
getFaces()
Get the number of faces of the die.
|
int |
getValue()
Get the current face value of the die.
|
int |
hashCode()
Returns a hash code for this object.
|
void |
roll()
Roll the die to a new random face value.
|
String |
toString()
Returns a string representation of this die, which includes
the number of faces and the current face value.
|
public Die()
1
and 6
, inclusive.public Die(int faces)
1
and
faces
, inclusive.
The number of faces must be greater than or equal to 2
.IllegalArgumentException
- if faces < 2
.faces
- The number of faces.faces >= 2
public Die(int faces, int value)
IllegalArgumentException
- if faces < 2
or
(value < 1 || value > faces)
faces
- The number of faces.value
- The initial face value.0 > value && value <= faces
public Die(Die d)
The created die is independent of the copied die; i.e., rolling the copied die will produce a different sequence of rolls than rolling the original die.
d
- the die to copypublic Die(int faces, Random rng)
1
and faces
, inclusive.
The number of faces must be greater than or equal to 2
.IllegalArgumentException
- if faces < 2
faces
- rng
- faces >= 2
public int getValue()
public int getFaces()
public void roll()
public int compareTo(Die other)
Die
has a current
face value less than the argument die. The result is positive
if this Die
has a current face value greater than
the argument die. The result is zero if both dice have the same
current face value.compareTo
in interface Comparable<Die>
the
- Die
to be compared.public String toString()
public int hashCode()