Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 5th, 2012  |  syntax: Java  |  size: 2.35 KB  |  hits: 155  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class PairOfDice
  2. {
  3.    protected Die d1, d2;
  4.    private int value1, value2, total;
  5.  
  6.    //-----------------------------------------------------------------
  7.    //  Creates two six-sided Die objects, both with an initial
  8.    //  face value of one.
  9.    //-----------------------------------------------------------------
  10.    public PairOfDice ()
  11.    {
  12.       d1 = new Die();
  13.       d2 = new Die();
  14.       value1 = 1;
  15.       value2 = 1;
  16.       total = value1 + value2;
  17.    }
  18.  
  19.    //-----------------------------------------------------------------
  20.    //  Rolls both dice and returns the combined result.
  21.    //-----------------------------------------------------------------
  22.    public void roll ()
  23.    {
  24.        d1.roll();
  25.        d2.roll();
  26.    }
  27.  
  28.    //-----------------------------------------------------------------
  29.    //  Returns the current combined dice total.
  30.    //-----------------------------------------------------------------
  31.    public int getDiceSum ()
  32.    {
  33.            total = getDie1() + getDie2();
  34.       return total;
  35.    }
  36.  
  37.    //-----------------------------------------------------------------
  38.    //  Returns the current value of the first die.
  39.    //-----------------------------------------------------------------
  40.    public int getDie1 ()
  41.    {
  42.       return d1.getFaceValue();
  43.    }
  44.  
  45.    //-----------------------------------------------------------------
  46.    //  Returns the current value of the second die.
  47.    //-----------------------------------------------------------------
  48.    public int getDie2 ()
  49.    {
  50.       return d2.getFaceValue();
  51.    }
  52.        
  53.         //-----------------------------------------------------------------
  54.    //  Sets the FaceValue of the first die.
  55.    //-----------------------------------------------------------------
  56.         public void setDie1 (int value)
  57.         {
  58.                 d1.setFaceValue(value);
  59.         }
  60.        
  61.         //-----------------------------------------------------------------
  62.    //  Sets the FaceValue of the second die.
  63.    //-----------------------------------------------------------------
  64.         public void setDie2(int value)
  65.         {
  66.                 d2.setFaceValue(value);
  67.         }
  68.        
  69.         //-----------------------------------------------------------------
  70.    //  Sets the FaceValue of the second die.
  71.    //-----------------------------------------------------------------
  72.         public String toString()
  73.    {
  74.         String result = "You rolled a " + total;
  75.  
  76.         return result;
  77.    }
  78.        
  79. }