Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 3: Matrix Library We will be creating a class which will be given a 2-D array when instantiated, and then implement various methods to

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Part 3: Matrix Library We will be creating a class which will be given a 2-D array when instantiated, and then implement various methods to perform operations on the 2-D array. Create the class with the following API. Then write main program to test all methods of your class. Please make sure your main method to test Matrix Library is in another class file and not in the Matrix class file! public class Matrix private boolean[[] matrix; private final int NUMROW; private final int NUMCOL; public Matrix(boolean[][ m) {} public String toString() public Matrix transposeMatrix() {} public boolean is Square Matrix( public Matrix rotateClockwise() { } public Matrix rotate CounterClockwise() { } public String percentage True() { } public boolean isEqual (Matrix m){} 1. public Matrix(boolean[Ill m) { } a. Initialize the NUMROW and NUMCOL variables. These are the row and column dimensions of m. b. The constructor should initialize the boolean(( matrix. C. Do not assume the input to the constructor is a NxN matrix The constructor and other methods need to work on matrices that have any column and row sizes. Methods should work on 4x4s, 4x2s, 7x5s, etc. 2. public String toString() { } a. returns a string value of the entire matrix. To receive full points, string must be in this form: Each value should have a comma and a space except the last one. There should be no space before the closing bracket. True is 1, false is O. 4x4 matrix (1, 1, 1, 1 0,1,0,1 0, 1, 1, 1 1, 1, 0, 1) 2x4 matrix [0, 1, 1, 1 1,1,0, 1] 3. public Matrix transposeMatrix() {} a. Returns the transpose of the instance field matrix as a new Matrix object b. Include these two matrices below in your test cases for this method. The transpose of a matrix is a new matrix whose rows are the columns of the original. (This makes the columns of the new matrix the rows of the original). Here is a matrix and its transpose: 15 4 3 (404) 17 10 3 15 4 3 4 0 4 7 10 3/ Another way to look at the transpose is that the element at row r column c in the original is placed at row c column r of the transpose. The element are of the original matrix becomes element acr in the transposed matrix. 5 4 4 0 7 10 - 5 4 4 7 0 10 -1 8 1-1 8 4x4 matrix (1, 1, 1,1 0,1,0,1 0, 1, 1, 1 1,1,0, 1] It should return the following as output: 4x4 matrix (1, 0, 0,1 1, 1, 1, 1 1, 0, 1,0 1, 1, 1, 1) 4. public boolean is Square Matrix() () a. returns true if the instance field matrix is a square matrix i.e., NUMROW is equal to NUMCOL; otherwise returns false 5. public Matrix rotateClockwise() { } a. Returns the instance field matrix rotated 90 to the right Example: 1, 1, 1, 1 1,1,0,0 1, 1, 1, 1] (1, 1, 1 1, 1, 1 1,0,1 1, 0, 1] 6. public Matrix rotate CounterClockwise() () a. Returns the instance field matrix rotated 90 to the left. Example:[ 1,1,1 1,1,1 1,0,1 1, 0, 1) (1, 1, 1, 1 1,1,0,0 1,1, 1, 1) 7. public String percentage True) {} a. Returns the percentage of indices that are true in the instance field matrix. b. b. For simplicity, always round up to the nearest whole percentage. Example: "50%" 1,1,1,1 0,0,0,0 0,0,0,0 1, 1, 1, 1] 8. boolean is Equal (Matrix m) a. returns true if the instance field matrix is equal to given matrix m. The matrices will be equal if they have the same number of rows and columns and every value is also equal; otherwise return false 9. As always, use the main as a test client to test each function. Write JUnit tests for all methods. Note: where line breaks are added in your toString() method, they will need to be added in Junit tests as well. For example, below is a unit test of calling toString() on a 3x3 matrix with all false indices: assertEquals("[0, 0, 0 0, 0, 0 0, 0, 0)", my Matrix.toString())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions