Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a Java class called Matrix that has the following variables, constructors, and methods: -Declare two-dimensional matrix int [][] matrix, numRows, numCols to

You will write a Java class called Matrix that has the following variables, constructors, and methods:

-Declare two-dimensional matrix int [][] matrix, numRows, numCols to denote the number of rows and columns.

-Non-default constructor public Matrix (int n, int m) that initializes matrix with number of rows equal to n and number of columns equal to m.

-Method public Matrix add(Matrix mat) that adds the corresponding integer entries on this.matrix with values in mat and returns the resulting Matrix object. This operation succeeds only when the number of rows and columns of both matrices are equal, so make sure to check that before adding. If not, handle it via an appropriate exception. The result matrix is of the same dimensions as the ones added. What is the time-complexity of your method?

-Method public Matrix transpose() OR public static Matrix transpose(Matrix mat) that returns the transpose of matrix mat. The transpose of a matrix M is a matrix M with number of rows and columns and the values interchanged. What is the time-complexity of your method?

-Method public Matrix subtract(Matrix mat) that subtracts the corresponding integer entries from this.matrix with values in mat and returns the resulting Matrix object. This operation succeeds only when the number of rows and columns of both matrices are equal, so make sure to check that before adding. If not, handle it via an appropriate exception. The result matrix is of the same dimensions as the ones in the subtraction operation. There is an easier way to do this, so think about it. What is the time-complexity of your method?

-Method public Matrix scalarMult(int const) that returns a new Matrix object where each entry of this.matrix is multiplied by the value const. What is the time-complexity of your method? What is the time- complexity of your method?

-Method public void printMatrix() that prints out the contents of this.matrix to a file matrix_output.txt . This file has on the first line Matrix is of dimension m rows by n columns, followed by the contents of the matrix starting from row 0, and then row 1, etc., each row of values on a separate line.

-Method public static Matrix genMatrix(int m, int n) that creates a new matrix of size m x n whose [i][j]th entry is set equal to i+j. This can be used for testing purposes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions