Question: 2D Arrays Lab Basic Operations 1. Write an Array2D class that will have a two-dimensional array of any given size as an instance variable. Write

2D Arrays Lab Basic Operations 1. Write an Array2D class that will have a two-dimensional array of any given size as an instance variable. Write the constructor (it should take a two-dimensional array as a parameter) and printArray() method. Write methods to do the following using the 2D array (not empty): 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. public int max()returns the maximum element. public int min()returns minimum element. public double median() returns the median element (the element that occurs in the middle). Recall that median is calculated by averaging the two middle elements if the number of elements in a set is even. public int mode() returns the element that occurs most frequently (mode). You may assume there would be at least one mode in a set public double average()returns the average of all the elements in the array. public int closestToZero() returns the element closest to 0. public void biggerThanAverage()prints all the numbers greater than the average. Numbers are printed horizontally, separated by a single space. public int sumRow(int r) returns the sum of any row of elements or returns -1 if number is not legal public int sumCol(int c) returns the sum of any column of elements or returns -1 if the column number is not legal public int sumMain() returns the sum of the elements on the main diagonal or returns -1 if the matrix is not a square matrix public int sumMinor()returns the sum of the elements on the minor diagonal or returns -1 if the matrix is not square b. Write a Array2DRunner class Create a 5 x 5 integer array using an initialize list with elements from -9 to 9 (duplicates allowed) print the array in matrix form and test all the methods. Create a 10 x 10 integer array using random integers from -9 to 9 (duplicates allowed) print the array in matrix form and test all the methods.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!