package edu.humboldt.st10.cs235; /** (playing-with-package version) A GameDie object represents a single game die. It has a set number of sides, each numbered from 1 to the number of sides, and it can be rolled, which results in a number between 1 and the number of sides. It also has a top, whose value is initially 1, and afterwards is set to the value of the most-recet roll. adapted from C++ class Dice from Astrachan's "A Computer Science Tapestry", 2nd edition, pp. 214, 217 @author Owen Astrachan @author adapted by Sharon Tuttle @version 2015-12-02 */ public class GameDie { // data fields private int numRolls; private int numSides; private int top; /** construct a new die with the user-specified number of sides, with an initial top value of 1 @param desiredNumSides number of sides for this die */ public GameDie(int desiredNumSides) { numRolls = 0; numSides = desiredNumSides; top = 1; } /** return the die's number of sides @return number of sides of calling die */ public int getNumSides() { return numSides; } /** return the die's number of times rolled @return number of times calling die has been rolled */ public int getNumRolls() { return numRolls; } /** return the die's current top value @return value of top for calling die */ public int getTop() { return top; } /** roll this game die instance @return the value of this roll of this game die */ public int roll() { numRolls++; top = (int) ( (Math.random() * numSides) + 1.0 ); return top; } }