This section presents documentation of the application programming interface (API) for the Matrix class, as well as the source and test classes for this exercise.

To understand the use of the Matrix API, look at MatrixTest, a class that uses Matrix and is written for you.

Observe:

A matrix is a two-dimensional structure of numerical values aij, 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:

To add two matrices, they must have the same dimensions, i.e. the same number of rows and columns.

The result of adding matrices A and B is a matrix C of the same dimensions, where cij = aij + bij.

For example:

To multiply two matrices, the number of columns in the first matrix must equal the number of rows in the second matrix. Matrix multiplication is not commutative.

The result of multiplying an m×n matrix A and an n×p matrix B is an m×p matrix C where cij is the dot product of the ith row of A and the jth column of B.

For example,

Your tasks, in order: The set, get, add, and multiply methods must also throw MatrixException objects where appropriate.
First decide how to internally represent a matrix. Suggestion: Test the constructor, set, and get by running the testSetAndGet1 and testSetAndGet2 methods in the MatrixTest class. Note:
Now add index bounds testing to the get and set methods: Test your index bounds testing by running the testBounds test.
Two matrices are equal if they have the same dimensions and all elements are equal by the == test.

To check for matrix equality your equals method must iterate through the matrices' rows and columns. Suggestion:

Test your equality testing by running the testEquals test.
The add and multiply methods both require iterating through rows and columns, so they also benefit from abstraction by using just the API methods getRows, getColumns, and get.

Note that both testAdd and testMultiply catch MatrixException objects and indicate the exact wording of the relevant error messages when the number of rows and columns in the operand matrices do not meet the preconditions of the add or multiply methods.

Test your matrix addition and multiplication operations by running the testAdd and testMultiply methods.

When all test methods execute successfully your Test Results window should include:

To verify that your Matrix implementation throws MatrixException objects when appropriate, the catch clauses in the test methods print the error messages to System.out.

In addition to reporting that all 6 tests passed, your Test Results window should also include:

When finished, zip your project folder as your-login-LEX4.zip.

Email the zip file to your TA.