/** Die: simulate rolling a die
 * @author CPSC 111, Section 206, Spring 05-06
 * @version Jan 31, 2006
 * 
 * This is the new Die code, to simulate rolling a die, that we
 * refined in class on Jan 26. We have tested it, and improved it.
 *
 * <p> We wrote it in several steps, starting at the whiteboard - not
 * starting with typing code! First, we talked about the functionality
 * that we wanted to support, then turned that into a UML diagram. 
 * Finally, we typed in some code to implement that diagram.

 *
 * <p> As we wrote the RollDice class to test it, we refined our
 * design to include a second constructor that took the number of
 * sides as input. After realizing that we needed the same
 * functionality in both that new constructor and the setSides method,
 * we decided to call the setSides method from the constructor rather
 * than duplicating code in two places.
 */ 

import java.util.Random;

public class Die
{
    /** 
	@param sides store the number of sides in the die
    */
    private int sides;
    final int DEFAULT_NUMBER_OF_SIDES = 6;
 
    /** Constructor, with no initialization information
     */
    public Die() 
    {
	setSides(DEFAULT_NUMBER_OF_SIDES);
    }

    /** Constructor, initializing number of sides
	@param numSides number of sides for the die
    */
    public Die(int numSides) {
        // sides = numSides;
        // duplicating code isn't a great idea!
        setSides(numSides);
    }

    /**
       Sets the die shape, thus the range of values it can roll.
       @param numSides the number of sides of the die
    */
    public void setSides(int numSides)
    {
        sides = numSides;
    }

    /**
       Gets the number of sides of the die. 
       @return the number of sides of the die
    */
    public int getSides()
    {
        return sides;
    }

    /**
       Generate which side of the die is up after a virtual roll
       @return value rolled
    */
    public int roll()
    {
        Random gen = new Random();
        return gen.nextInt(sides) +1; // number from 1 - numsides
    }
}

