<html>
<head>
<title>Die class</title>
</head>

<body>
<pre>
/*******************************************************************************
Author:           Rebecca Hasti, hasti@cs.wisc.edu
                  copyright 2001, all rights reserved
Course:           CS 302

Compiler:         Metrowerks CodeWarrior (JDK 1.2)
Platform:         Windows (NT or 95 or 2000)
*******************************************************************************/

/**
 * An object of the Die class represents a die with a given number of sides.
 *
 * Bugs:	none known
 **/
class Die {

	////////////////////////////////////////
	// Data Members
	////////////////////////////////////////
	
	private int numSides;         // number of sides the die has
	private int currentValue;     // value showing on the "top" side
	public static final int DEFAULT_NUM_SIDES = 6;  
	                              // default number of sides

	////////////////////////////////////////
	// Constructors
	////////////////////////////////////////
<font color=red>
	/**
	 * Constructs a die with n sides and sideUp showing.
	 * Note: If the n < 1, a die is constructed with 1 side.
	 * Note: If n < sideUp, sideUp is set to n.
	 * @param n the number of sides (if n < 1, number of sides set 1)
	 * @param sideUp the side initially showing
	 **/
	public Die(int n, int sideUp) { 
		if (n < 1)
			n = 1;
		if (sideUp > n)
			sideUp = n;
    		numSides = n; 
		currentValue = sideUp;
  	}</font>

	/**
	 * Constructs a die with n sides.
	 * Note: If the n < 1, a die is constructed with 1 side.
	 * @param n the number of sides (if n < 1, number of sides set 1)
	 **/
	public Die(int n) { 
		if (n < 1)
			n = 1;
    		numSides = n; 
    		<font color=red>roll()</font>;
  	}

	/**
	 * Constructs a die with the default number of sides.
	 **/
	public Die() {
		numSides = DEFAULT_NUM_SIDES;
    		<font color=red>roll()</font>;
	}
  	
	////////////////////////////////////////
	// Public Methods
	// 
	// 		void	rollDie()
	// 		int 	getValue()
	// static 	void 	describeDieClass
	//////////////////////////////////////// 
 
 	/** 
 	 * This method simulates the rolling of a die.  A new side up is
 	 * computed using a random number generator.
 	 **/
  	public void roll() {
    		currentValue = (int)Math.floor(Math.random() * numSides + 1);
  	}
  
  	/**
  	 * Returns the current side up on the die.
  	 * @return the current side up
  	 **/
  	public int getValue() {
    		return currentValue;
  	}
  	
  	/**
  	 * Describes the die class to the user (on the console window).
  	 **/
	public static void describeDieClass() {
		System.out.println("The Die class can be used to represent dice.");
		System.out.println("The number of sides a Die object is to have");
		System.out.println("is passed to the constructor.  A die may be");
		System.out.println("rolled and the value on its top side obtained.");
	}
} // end class Die
</pre>
</body>
</html>

