public class Die
extends java.lang.Object
Constructor and Description |
---|
Die()
Creates a new Die object with the default number (6) of sides.
|
Die(int s)
Creates a new Die object with
s number of sides. |
Modifier and Type | Method and Description |
---|---|
int |
getSides()
Returns the number of sides in a class instance.
|
int |
roll()
Simulates rolling a single die.
|
int |
roll(int n)
Simulates rolling a number of dice with a number of sides
represented by this instance.
|
void |
setSides(int s)
Accessor to set the number of sides in a class instance.
|
java.lang.String |
toString() |
public Die(int s)
s
number of sides.s
- the number of sides represented by this
Die object.public Die()
public int getSides()
public void setSides(int s)
s
- the new number of sides for the Die.public int roll(int n)
n
* 1 to n
* the number of sides in
this Die instance.n
- number of dice to roll.public int roll()
getSides().
public java.lang.String toString()
toString
in class java.lang.Object