import java.util.Random;

/**************************************************************
	Die represents a single game die
**************************************************************/
public class Die implements Comparable<Die>
{
   // defines the kind of dice we are using
   public static final int LO = 1;
   public static final int HI = 6;

	private Random  gen;
	private int 	 face;
	
	/**************************************************************
		Constructor for a Die
		@param gen The random generator to use for this Die
	**************************************************************/
	public Die(Random gen)
	{
		this.gen = gen;
		roll();
	}
   
   /**************************************************************
		Constructor for a Die which does not use a random generator
      and does not roll the Die. Used for testing.
		@param value The value to set this Die to
	**************************************************************/
	public Die(Random gen, int value)
	{
      setFace(value);
	}


	/**************************************************************
		roll simulates a single roll of the die
		@return the face value of the die.
	**************************************************************/
	public int roll()
	{
		face = gen.nextInt(HI) + 1;
		return face;
	}
	/**************************************************************
		getFace simulates looking at the die face
		@return the face value of the die.
	**************************************************************/	
	public int getFace()
	{
		return face;
	}
   /**************************************************************
	 setFace sets the face value of the Die
    used to test game play and for duplicating a set of dice.
    If the value is out of bounds, then do nothing
    
    @param value The new face value
    @return the face value of the die.
    @throws IllegalArgumentException If the value is out of 
            the range for this Die.
	**************************************************************/	
	public int setFace(int value)
	{
	   if(value >= LO && value <= HI)
         face = value;
      else
         throw new IllegalArgumentException("Bad value" + value);
      return face;
	}
	
	/************************************************************
	 * compareTo compares two Die objects on the basis of their face
	 * values. 
	 * @return a positive number if this > other; 0 if they are the
	 *        same and a negative number if they are different.
	 ************************************************************/
	public int compareTo(Die other)
	{
		return this.face - other.face;
	}

}		