/** A simple class that simulates a fair die. @author Jed Yang and friends, 2017-01-06 */ import java.util.Random; public class Die { // class variable private static int numberCreated = 0; // instance variables, private private Random rand; private int value; private final int sides; public Die(int sides) { rand = new Random(); this.sides = sides; value = 1; numberCreated++; System.out.println("Created die #" + numberCreated + " with " + sides + " sides."); } public Die() { this(6); // call the constructor above to created 6-sided die } /* Roll the die. */ public void roll() { value = rand.nextInt(sides) + 1; } /** Set the value. */ public void setValue(int newValue) { // check if newValue is <= 6 value = newValue; } /** Get the value. @return the value of the die. */ public int getValue() { return value; } }