/** This is the Die class -- the attributes are the number of sides and * a random number generator, which can be found in Java's Random class. * The only operation we will want to do with a die is roll it. */ import java.util.Random; public class Die { private Random generator; private int sides; /** Initial value constructor for a "die" -- create a die that has * the specified number of sides. */ public Die (int s) { generator = new Random(); sides = s; } /** The roll function here simulates the action of rolling a single die. * We use the nextInt(n) function in the Random class, which returns a * random integer between 0 and n-1 inclusive. We want the range to be * 1-n, so we'll add one. */ public int roll() { return generator.nextInt(sides) + 1; } }