Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java code include a JUnit4 test, main for all method What you will learn: Array (One Dimensional and 2 Dimensional) and ArrayList Writing class Unit

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

java code

include a JUnit4 test, main for all method

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 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 Counter Clockwise() { } 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 isEqual (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 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 Counter Clockwise() { } 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 isEqual (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_2

Step: 3

blur-text-image_3

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

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

What type of campaign financing reform would you recommend?

Answered: 1 week ago

Question

4-6 Is there a digital divide? If so, why does it matter?

Answered: 1 week ago