Question: Program requirements: Matrix class The private field is a two dimensional array of int values Since the size is not yet known, this can be

Program requirements: Matrix class
The private field is a two dimensional array of int values
Since the size is not yet known, this can be set up as follows:
\table[[6,//field for two dim array],[7,private int[][] matrixVals;]]
The constructor calls the setMatrixVals(mVals) setter method to assign the correct information to the private field
The setMatrixVals(mVals) setter method must make a copy of the parameter
This copy becomes the private field
The getMatrixVals() getter method must return a copy of the field
Program requirements (continued): Matrix class
The sameSize(m2) method returns true if the this object and the parameter Matrix object (i.e.m2) have the same number of rows and columns
Else returns false
The transpose() method returns the this object transposed
Therefore, the rows become the columns and the columns become the rows
The scalarMult(scVal) method returns the Matrix object that is obtained by multiplying all elements of the this object by the scVal (data type int) value of the parameter
The add(m2) method returns the Matrix object that results from adding the this object and the parameter Matrix object
The toString() method returns a consistent representation of the two dimensional array (i.e. the private field)
Program requirements (continued): Matrix class
The getMatrixVals() getter method must return a copy of the field
Why is this important?
If the method returns only the name of the array, it is actually returning the address in memory
Therefore, any other method that has access to this address can potentially change the information stored at that address.
Therefore, to protect the security of the data, we must return a copy and not the address
The same concept applies to the setter method, which is why a copy of the parameter array must be made and assigned to the private field
Note that this will necessitate implementing a nested for loop and copying each value in the correct place
 Program requirements: Matrix class The private field is a two dimensional

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!