Class Die

java.lang.Object
  |
  +--Die

class Die
extends java.lang.Object

Die.java The Die class models a die with a specified number of sides.

Version:
8/10/2001
Author:
Grant William Braught, Dickinson College

Constructor Summary
Die()
          Construct a six sided die.
Die(int sides)
          Construct a sides sided die.
 
Method Summary
 int getNumSides()
          Get the number of sides on this Die.
 int getSide()
          Get the side of the die that is currently showing.
 int roll()
          Roll the die.
 java.lang.String toString()
          Generate a string representation of this Die instance.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Die

public Die()
Construct a six sided die. The Die will have side 1 facing up by default.

Die

public Die(int sides)
Construct a sides sided die. The Die will have side 1 facing up by default.
Parameters:
sides - the number of sides on the die.
Method Detail

getNumSides

public int getNumSides()
Get the number of sides on this Die.
Returns:
the number of sides on this Die.

getSide

public int getSide()
Get the side of the die that is currently showing.
Returns:
the side of the die that is currently showing.

roll

public int roll()
Roll the die.
Returns:
the side of the die that is showing after the roll.

toString

public java.lang.String toString()
Generate a string representation of this Die instance. This representation will be similar to:
  
    Die: Number of sides=6
         Current side=4
 
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this Die.