Yahtzee Die Submission
import java.util.*;
public class YahtzeeDie
{
/* instance data should include a Random number generator, a numOfSides which
contains the number of sides the die has, value which is the current value
of the die and isFrozen which is true if die is frozen, false if not */
/* your code here */
/**
* @var generator for generating random numbers
*/
private Random generator;
/**
* @var currentValue of die
*/
private int currentValue;
/**
* @var numOfSides
* indicates the number of sides for die
*/
private int numOfSides;
/**
* @var isFrozen
* indicates whether or not the die is frozen
*/
private boolean isFrozen;
/* initialize the Random obect appropriately, initialize an int containing the value to 0,
a boolean isFrozen to false and numOfSides to the argument passed in */
public YahtzeeDie(int sides)
{
this.generator = new Random();
this.currentValue = 0;
this.isFrozen = false;
this.numOfSides = sides;
}
/* Set the new value for the die using the Random object */
public void rollDie()
{
int newValue = this.generator.nextInt(this.numOfSides) + 1; // add +1 because lower bound (0) is inclusive and upper bound is exclusive
this.currentValue = newValue;
}
/* Gets the current die value */
public int getValue()
{
return this.currentValue;
}
/* Set the value of isFrozen to true */
public void freezeDie()
{
this.isFrozen = true;
}
/* Set the value of isFrozen to false */
public void unfreezeDie()
{
this.isFrozen = false;
}
/* Return true if die is frozen, false if it is unfrozen */
public boolean isFrozen()
{
if ( ! this.isFrozen) {
return false;
}
return true;
}
}