<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/** A Dice (or Die) */
class Dice {

   private int top;    // top face
   private int sides;  // number of sides
   
   /** A Dice has numSides sides and the top face is random */
   public Dice(int numSides) {
     sides= numSides;
     roll();
   }

   /** top gets a random value in 1..sides */
   public void roll() {
     setTop(randInt(1,getSides())) ;
   }
   
   /** = random int in low..high */
   public static int randInt(int low, int high) {
     return (int) Math.floor(Math.random()*(high-low+1)+low);
   }

   /** Set top to faceValue  */
   protected void setTop(int faceValue) { top= faceValue; }
   
   /** = Get top face */
   public int getTop() { return top; }
 
   /** = Get number of sides */
   public int getSides() { return sides; }  
   
   /** = String description of this Dice */
   public String toString() {
     return  getSides() + "-sided dice shows face " + getTop();
   }
}
</pre></body></html>