Question: Die is a (six sided) cube with the numbers 1 - 6 labeling each of its 6 (sides) faces. Whatever label is on the side

Die is a (six sided) cube with the numbers 1 - 6 labeling each of its 6 (sides) faces. Whatever label is on the side that faces up is considered to be the value of the die (at any given time).

Write a complete class named Die that:

  • Includes an appropriate instance count variable.
  • Makes "correct" use of the public and private modifiers on both variables and methods.

  • Makes "correct" use of the static modifier on both variables and methods.

  • Includes a standard accessor and mutator for each of the class's instance (non-static) or class (static) variables.
  • Adheres to the rule that only the class's accessor and mutator methods directly access the class's instance (non-static) or class (static) variables.

  • Includes the standard default (0-arity), specifying and copy constructors.
  • Adheres to the rule that the default (0-arity) and copy constructors simply call the specifying constructor with appropriate arguments.

  • Includes the standard equals and clone methods.

The following Driver Class DieDriver must compile given your Die class.

public class DieDriver

{

public static void main(String[] args)

{

System.out.println("dieCnt = " + Die.getDieCnt());

Die d1 = new Die();

Die d2 = new Die(4);

Die d3 = new Die(d2);

Die d4 = d1.clone();

System.out.println("dieCnt = " + Die.getDieCnt());

System.out.println("d1 = " + d1.getUpSide());

System.out.println("d2 = " + d2.getUpSide());

System.out.println("d3 = " + d3.getUpSide());

System.out.println("d4 = " + d4.getUpSide());

if ( d1.equals(d2) )

System.out.println("d1 equals d2");

else

System.out.println("d1 does not equals d2");

if ( d2.equals(d3) )

System.out.println("d2 equals d3");

else

System.out.println("d2 does not equals d3");

}

}

The run of the Driver Class DieDriver, given your Die class, will produce the following output (exactly):

dieCnt = 0;

dieCnt = 4;

d1 = 1

d2 = 4

d3 = 4

d4 = 1

d1 does not equals d2

d2 equals d3

View keyboard shortcuts

EditViewInsertFormatToolsTable

12pt

Paragraph

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!