Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q1: please fill in the empty place (red), and run the code to get the output.//*

ID: 3772194 • Letter: Q

Question

Q1: please fill in the empty place (red), and run the code to get the output.//********************************************************************// RollingDice.java       Author: Lewis/Loftus//// Demonstrates the creation and use of a user-defined class.//********************************************************************public class RollingDice{   //-----------------------------------------------------------------   // Creates two Die objects and rolls them several times.   //-----------------------------------------------------------------   public static void main (String[] args)   {      Die die1, die2;      int sum;      die1 = new Die();      die2 = new Die();      die1.roll();      die2.roll();      System.out.println ("Die One: " + die1 + ", Die Two: " + die2);      die1.roll();      die2.setFaceValue(4);      System.out.println ("Die One: " + die1 + ", Die Two: " + die2);      sum = die1.getFaceValue() + die2.getFaceValue();

Explanation / Answer

public class RollingDice
{
   //-----------------------------------------------------------------
   // Creates two Die objects and rolls them several times.
   //-----------------------------------------------------------------
   public static void main (String[] args)
   {
       Die die1, die2; // instantiation of 2 Die objects
      int sum;

      // the point is that Die is a class written by authors of book,
      // not a standard class in a Java library

      die1 = new Die(); // constructor
      die2 = new Die();

      die1.roll(); // roll die1
      die2.roll();
      System.out.println ("Die One: " + die1 + ", Die Two: " + die2);

      die1.roll();
      die2.setFaceValue(4); // sets die2's face value
      System.out.println ("Die One: " + die1 + ", Die Two: " + die2);

      sum = die1.getFaceValue() + die2.getFaceValue(); // access face values
      System.out.println ("Sum: " + sum);

      sum = die1.roll() + die2.roll();
      System.out.println ("Die One: " + die1 + ", Die Two: " + die2);
      System.out.println ("New sum: " + sum);
   }
}