Class Dice


  • public class Dice
    extends java.lang.Object
    Class that implements random dice.

    Have a look through the file to see how a simple object class is constructed. The dice class has a random number generator and an int number of sides. We can roll the die to get a random value in the game.

    See Also:
    Lab 4 Description, Dice is Singular of Dice
    • Constructor Summary

      Constructors 
      Constructor Description
      Dice(int sides)
      Create a new dice with a given number of sides.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int roll()
      Rolls our simulated dice.
      • Methods inherited from class java.lang.Object

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

      • Dice

        public Dice(int sides)
        Create a new dice with a given number of sides.
        Parameters:
        sides - the number of sides our dice should have
    • Method Detail

      • roll

        public int roll()
        Rolls our simulated dice.

        Uses a pseudorandom number generator to determine the side to return.

        Returns:
        the number the die rolled