Question: 2D Arrays Lab 1 Basic Operations Write an Array2D class that will have a two-dimensional array of ints of any given size as an instance
2D Arrays Lab 1 Basic Operations
Write an Array2D class that will have a two-dimensional array of ints of any given size as an instance variable.
Write a constructor that accepts the number of rows and the number of columns in the array. You can assume that the values passed in for rows and cols is greater than zero.
public Array2D(int rows, int cols)
Write a printArray method that prints out all the elements in the 2D array in matrix form.
public void printArray()
Write an initialize method that will fill the array with random numbers from a given range.
public void initialize(int low, int high)
Write an Array2DTester class.
Create a 3 x 3 integer array and then initialize the array with elements from -9 to 9 (duplicates allowed). Print out the array.
Create a 7 x 7 integer array and then initialize the array with elements from -9 to 9 (duplicates allowed). Print out the array.
Add the following methods to the Array2D class. Test incrementally (i.e. you should test each method after it is written and fix any errors before writing the next method.):
return the maximum element. public int max()
return minimum elements. public int min()
return the element that occurs most frequently. If there is more than one value with the greatest frequency, return the lowest number (mode) public int mode()
return the average of all the elements in the array. public double average()
return the sum of any row of elements. You can assume that the row passed in is valid public int sumRow(int row)
return the sum of any column of elements. public int sumCol(int col)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
