Class Die
- java.lang.Object
-
- Die
-
public class Die extends java.lang.ObjectThis class represents a single n-sided die. The top number of the die is called the "face value". You can roll the die or you can explicitly set the die to a particular face value.- Version:
- sp16
- Author:
- alchambers
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Die other)Compares this die to the other die.intgetFaceValue()Returns the current face value of the dieintroll()Simulates a roll of the dicevoidsetFaceValue(int newValue)Allows user to explicitly set the die to whatever value they wantjava.lang.StringtoString()Returns a String that summarizes the state of the die
-
-
-
Method Detail
-
roll
public int roll()
Simulates a roll of the dice- Returns:
- the number rolled
-
setFaceValue
public void setFaceValue(int newValue)
Allows user to explicitly set the die to whatever value they want- Parameters:
newValue- the new face value of the die
-
getFaceValue
public int getFaceValue()
Returns the current face value of the die- Returns:
- the current face value
-
toString
public java.lang.String toString()
Returns a String that summarizes the state of the die- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the state of the die
-
equals
public boolean equals(Die other)
Compares this die to the other die. The result is true if both die have the same number of sides and the same face value.- Parameters:
other- The die to compare against
-
-