Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use Java use JUnit 4 -> test explain every method Thank you I found there is the same question on the Chegg, but it only

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

use Java

use JUnit 4 -> test

explain every method

Thank you

I found there is the same question on the Chegg, but it only figures out questions 1 - 4 for matrix, and it doesn't work because it doesn't have the main and doesn't have a JUnit4 test.

so don't post the same answer. please.

What you will learn: Array (One Dimensional and 2 Dimensional) and ArrayList Writing class Unit Testing 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. 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 is Equal (Matrix m) {} 1. public Matrix(boolean[][] 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 0. 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: 1 5 4 7 4 0 10 3 4 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 arc of the original matrix becomes element acr in the transposed matrix. 15 4 IT 4 0 7 10 1- 18 5 4 7 4 0 10 -1 8 4x2 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 rotate Clockwise() { } 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()); What you will learn: Array (One Dimensional and 2 Dimensional) and ArrayList Writing class Unit Testing 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. 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 is Equal (Matrix m) {} 1. public Matrix(boolean[][] 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 0. 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: 1 5 4 7 4 0 10 3 4 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 arc of the original matrix becomes element acr in the transposed matrix. 15 4 IT 4 0 7 10 1- 18 5 4 7 4 0 10 -1 8 4x2 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 rotate Clockwise() { } 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 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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions