Question: Implement a class Matrix that represents a matrix of the form Here r and c are the number of rows and columns of the matrix.
Implement a class Matrix that represents a matrix of the form
Here r and c are the number of rows and columns of the matrix. Your class should support the following operations: Constructs a matrix with a given number of rows and columns. Gets and sets the element at a particular row and column position. Adds and multiplies two compatible matrices. (You may need to look up the definition for matrix addition and multiplication in a linear algebra book or on the Web.) As the internal representation, store the elements in a two-dimensional array: private double[][] elements; In the constructor, initialize the array as: elements = new double[r][c]; Then you can access the element at row i and column j as elements[i][j]. Based on above directions implement the class Matrix with required constructors, accessors and mutators. For matrix addition and multiplication implement them as instance methods, so the following code snippet works: Matrix matrix1 = new Matrix(3, 3); //Possible setter calls Matrix matrix2 = new Matrix(3, 3); //Possible setter calls Matrix product = matrix1.multiply(matrix2); //product contains the multiplication of matrix1 & matrix2. Remember multiply here is working as //an accessor thus it should not change the state of teither matrix1 or matrix2. Include proper @precondition, @postcondition, @invariant, @throws, @param and @return Javadoc tags wherever required. Make sure they appear in the Javadoc. Now implement a Junit Test class that will perform the testing on the class Matrixs methods. Include your Junit code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
