Question: Matrix Class Implementation A matrix is a two-dimensional structure of numerical values a i , j , where i is the (zero-origin) row index and
Matrix Class Implementation
A matrix is a two-dimensional structure of numerical values ai, j , where i is the (zero-origin) row index and j is the (zero-origin) column index. If r is the number of rows and c is the number of columns in a matrix A, then it has the form:
Figure 1: A matrix of r rows and c columns.
You are to design and implement a Java Class named Matrix, here is what you need to do.
Include 3 attributes, rows, columns and a 2D array for the actual matrix.
A constructor that takes the number of rows and columns of the 2D array as parameters from client and instantiates it.
A method called copyMatrix that returns a copy of a Matrix object. (Do not clone!!)
A method called equals that returns true if two Matrix objects are the same, otherwise returns false. Two Matrix objects are the same if they have the same number of rows and columns, and the value Ai, j of Matrix As 2D array is equal to value Bi, j of Matrix Bs 2D array.
A toString method that returns a properly formatted String that contains at- tributes of a Matrix object. A toString method in a Java class always returns a String that contains the current state of the Object. The current state is represented by Objects attributes.
A method called scalarMultiply to multiply a Matrix by scalar in which every value Ai j in Matrix As 2D array is multiplied by a scalar value k. See details in Figure 2. You only need to pass value k as a parameter to this method.
A method to multiply called multiply a Matrix by another Matrix. If the number of columns in Matrix As 2D array is not equal to the number of rows in Matrix Bs 2D array, the method should throw an Exception, otherwise it should perform the multiplication between the two 2D arrays in the Matrix objects and return a resulting Matrix object. See details in Figure 3, Figure 4 and Figure 5.
Figure 2: A matrix of 2 rows and 3 columns is multiplied by the scalar value 3.
Figure 3: A matrix of 2 rows and 3 columns is multiplied by a matrix of 3 rows and 1 column.
Figure 4: A matrix of 4 rows and 2 columns cannot be multiplied by a matrix of 3 rows and 5 columns.
Figure 5: A matrix of 3 rows and 3 columns can be multiplied by a matrix of 3 rows and 2 columns
Write a client code (a Java class with main method) to test all methods in Matrix class. You must test the following
Instantiate several Matrix objects of different rows/columns.
Make a Matrix copy from an existing Matrix instance
Test the equals method with Matrix objects that are actually equal, and with the Matrix objects that are not equal. Must output properly labeled state- ments.
Display several of the Matrix objects using toString method.
Display a Matrix object that is before and after multiplying by a valid integer scalar value using scalarMultiply
Display a Matrix object that is before and after multiplying by 0 as the scalar value.
Test the method multiply wirh Matrix by Matrix multiplication with at least three sets of different Matrix objects that test different outcomes of the method, including the Exception. Know your answers BEFORE you test!
Turn in properly documented Java programs (actual .java source programs client and class), outputs. Also turn in the java programs and output in a docx document.
Be sure to include file comment block and method comment blocks.
Java please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
