Question: Given the Die class: public class Die { private int face; public Die(int x) { face=x; } public void setFace(int f) { face = f;

Given the Die class:

public class Die {

private int face;

public Die(int x) {

face=x;

}

public void setFace(int f) {

face = f;

}

public int getface() {

return face;

}

}

1. Write a class named Matrix that:

  • has a data named array, which is a two dimensional square array of Die objects, i.e., both rows and columns are the same number.
  • a constructor, which takes an integer parameter named size representing the arrays dimensions, and initializes all the elements of the array to dice with face=1, except for the main diagonal (the row and column indices are the same) to dice with face=5.
  • an equals method that checks whether the object is equal to another Matrix object.

2. Write a Java application named TestMatrix that instantiates two objects of the Matrix class and checks whether the two objects are equal.

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!