/** Die: simulate rolling a die
 * Author: CPSC 111, Section 206, Spring 05-06
 * Date: Jan 26, 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
{

    private int sides;

    public Die() 
    {}

    public Die(int numSides) {
        // sides = numSides;
        // duplicating code isn't a great idea!
        setSides(numSides);
    }

    public void setSides(int numSides)
    {
        sides = numSides;
    }

    public int getSides()
    {
        return sides;
    }

    public int roll()
    {
        Random gen = new Random();
        return gen.nextInt(sides) +1; // number from 1 - numsides
    }
}

