import java.util.Random; //Warn Java we want to use Random /** * The Die class models a die of the sort you'd roll: It * can be created with as many sides as you wish, and has * a roll method that returns an appropriate random result. */ public class Die { private int numSides; // The number of sides on this die private Random rng; // The die's random number generator /** * Constructor for objects of class Die. The default constructor * (this one, since it takes no parameters) will create a six-sided * die. */ public Die() { rng = new Random(); numSides = 6; } /** * This constructor creates a Die object with the specified number * of sides. * @param sides The number of sides our virtual Die should have. */ public Die(int sides) { rng = new Random(); numSides = sides; } /** * Simulates a roll of this Die instance. * @return A random value in the range [1..number of sides] */ public int roll() { int value = rng.nextInt(numSides)+1; //System.out.println("Roll is about to return "+value); return value; } /** * Returns the number of sides on this die. * @return The number of sides. */ public int getNumSides() { return numSides; } }