Dr Java Matrix Assignment
CS 110 Introduction to Computer Science
Outside Lab Programming Assignment 5
Due: Thursday December 6, 2018 at 11:59 PM
Creating a Matrix Class
In this assignment, you are to create the class Matrix to represent two‐dimensional double arrays. The
class will have the data members:
double [][] matrix
int numRows
int numCols
Constructors
Null constructor – create a 5x5 matrix
Parameterized constructors:
(int numR, int numC) – creates a numR x numC matrix
(Matrix a) – creates a deep copy of the matrix a
(double [][] mat) – create an object of type matrix whose contents is
mat
Mutators:
void fill (double value) – sets the contents to value
void scalarMult (double value) – multiples each element by value
Manipulators:
Matrix addMatrix (Matrix a) – Two matrices can be added together if they are
the same size. This method will add (if possible) two matrices together element
by element and return the result. It will not modify either matrix used in the
addition. If addition is not possible, the method should return null.
Matrix multMatrix (Matrix a) – Two matrices A and B can be multiplied A*B if
the number of columns of A is equal to the number of rows of B. This method
will multiple (if possible) the two matrices together creating and returning the
result. It will not modify either matrix used in the operation. If multiplication is
not possible, the method should return null.
void displayMatrix() – will display the matrix in row major order, without
modifying the matrix
Matrix transpose() – will create and return the transpose of the matrix, without
modifying the original matrix
For more information visit https://en.wikipedia.org/wiki/Matrix_(mathematics).
Accompanying this lab is the skeleton of the class Matrix. You cannot modify or enhance the class in any
way.
Your lab instructor will supply a tester class to use with your class to demonstrate your class works
correctly.