Class Die
- java.lang.Object
-
- Die
-
public class Die extends java.lang.Object
This 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 boolean
equals(Die other)
Compares this die to the other die.int
getFaceValue()
Returns the current face value of the dieint
roll()
Simulates a roll of the dicevoid
setFaceValue(int newValue)
Allows user to explicitly set the die to whatever value they wantjava.lang.String
toString()
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:
toString
in 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
-
-