Class 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
    • Constructor Summary

      Constructors 
      Constructor Description
      Die()
      This is the default constructor.
      Die​(int sides)
      This constructor creates a new n-sided die
    • 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 die
      int roll()
      Simulates a roll of the dice
      void setFaceValue​(int newValue)
      Allows user to explicitly set the die to whatever value they want
      java.lang.String toString()
      Returns a String that summarizes the state of the die
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Die

        public Die()
        This is the default constructor. It defaults to a 6-sided die.
      • Die

        public Die​(int sides)
        This constructor creates a new n-sided die
        Parameters:
        sides - The number of sides 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 class java.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