Question: Write a class named Array2DAlgorithms. In the class write: an equals method that accepts two 2D integer arrays as parameters and returns true if the
Write a class named Array2DAlgorithms.
In the class write: an equals method that accepts two 2D integer arrays as parameters and returns true if the arrays contain the same elements in the same order. If the arrays are not the same length in either dimension, your method should return false. a printArray method that takes a 2D integer array as a parameter and prints each row of the array on a separate line. Each row should be contained in brackets with each element separated by a comma followed by a space. a method called matrixAdd (Textbook Ex. 7-19) that accepts a pair of two-dimentional arrays of integers as parameters, treats the arrays as two-dimensional matrices, and returns their sum. The sum of two matrices A and B is a matrix C, where for every row i and column j, C[i][j] = A[i][j] + B[i][j]. You may assume that the arrays passed as parameters have the same dimensions.
Do NOT use the Arrays class when writing your methods.
In your main method, create two 3x4 2D integer arrays, both with the following elements:
row 1: 1, 2, 3 ,4 row 2: 5, 6, 7, 8 row 3: 9, 10, 11, 12 Call your equals method using these arrays as parameters and print the result with meaningful text. Call the matrixAdd method using these arrays as parameters and print the result using your printArray method. The output from your program should be similar to the following:
Arrays: [1, 2, 3, 4] [5, 6, 7, 8] [9, 10, 11, 12] and [1, 2, 3, 4] [5, 6, 7, 8] [9, 10, 11, 12] are equal.
and their sum is:
[2, 4, 6, 8] [10, 12, 14, 16] [18, 20, 22, 24]
You may not use Arrays.equals or Arrays.deepEquals.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
