/** * This class models a simple die object, which can have any number of sides. * @author Dave Reed * @version 9/1/04 */ public class Die { private int numSides; private int numRolls; /** * Constructs a 6-sided die object */ public Die() { numSides = 6; numRolls = 0; } /** * Constructs an arbitrary die object. * @param sides the number of sides on the die */ public Die(int sides) { numSides = sides; numRolls = 0; } /** * Gets the number of sides on the die object. * @return the number of sides (an N-sided die can roll 1 through N) */ public int getNumberOfSides() { return numSides; } /** * Gets the number of rolls by on the die object. * @return the number of times roll has been called */ public int getNumberOfRolls() { return numRolls; } /** * Simulates a random roll of the die. * @return the value of the roll (for an N-sided die, the roll is between 1 and N) */ public int roll() { numRolls = numRolls + 1; return (int)(Math.random()*getNumberOfSides() + 1); } }