
public class Dice {

	//constant
	// public - accessible outside of this class
	//   Dice.DEFAULT_SIZE
	// static part of the class instead of part
	//    of each object
	// final can't change it
	public static final int DEFAULT_SIDES = 6;
	
	// there is one shared by all objects
	private static int NUM_DICE = 0;
	
	//data:
	// fields or data fields
	// instance variables
	//  data member
	// member variable
	
	// number of sides on the die (Dice object)
	private int sides;
	
	// current value (number facing up)
	private int currentValue;
	
	
	//actions - methods
	//constructor - called using new
	// name is the same as the class
	// no return type (not void)
	public Dice(int sides) {
		//this refers to the object being created
		//make the distinction between instance variable and parameter
		//this.sides = sides;
		setSides(sides);
		//this.currentValue = 1;
		roll();
		
		NUM_DICE++;
	}
	
	//a 0-parameter constructor for
	// a 6-sided dice
	//overload
	public Dice() {
		//call the other constructor with this
		// must be the first executable line
		this(DEFAULT_SIDES);
		//sides = 6;
		//currentValue = 1;
	}
	
	
	//roll the dice
	public int roll() {
		currentValue = (int)(Math.random()*sides) + 1;
		return currentValue;
	}
	
	//getters
	
	//get sides  - return the number of sides
	public int getSides() {
		return sides;
	}
	
	public int getCurrentValue() {
		return currentValue;
	}
	
	//setters
	//set the number of sides to s
	public void setSides(int s) {
		if(s > 0) {
			sides = s;
		}
	}
	
	public String toString() {
		return String.format("%d-sided die (%d)", sides, currentValue);
	}
	
	
	public static int getNumDice() {
		return NUM_DICE;
	}
	
}
