Question: LANGUAGE: JAVA A matrix is a rectangular array of numbers arranged in rows and columns. Each number in a matrix is referred to as a
LANGUAGE: JAVA

A matrix is a rectangular array of numbers arranged in rows and columns. Each number in a matrix is referred to as a matrix element or an entry. Two matrices can be added provided that they have the same dimension, same number of rows and columns. Taking the sum of two matrices is accomplished by adding the corresponding entries. See the example shown below. 5+2 i 9]+[ 1 9 =[ 4 11] Considerations: The following Exception classes are declared: class InvalidMatrixException extends Exception { public InvalidMatrixException(String msg) { super (msg); } } class IncompatibleMatricesException extends Exception { public IncompatibleMatricesException(String msg) { super (msg); } } Complete the Java program that computes the sum of two matrices. Note: all the methods shown below are to be defined as instance methods. public #01 addMatrix(int[][] ni, int[][] m2) throws InvalidMatrixException, IncompatibleMatricesException { // check if nl and m2 are rectangular matrices if (!(check Rectangular Matrix(mi) #02 checkRectangular Matrix(m2))) { #03 InvalidMatrixException("Error: One of the matrices is not a rectangular array."); } // check if mi and m2 are of the same dimension int miRows - m1.length; int micols - mi[@].length; int m2Rows - m2.length; int m2Cols - m2[0].length; if (miRows != m2 Rous #04 micols != m2Cols) { #03 IncompatibleMatricesException("Error: Matrices are not of the same dimension."); } #01_result = new int[m1Rows] (01Cols]; for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
