Question: The goal of this assignment is to write java programs in which the student is able to manipulate 2D arrays (creating 2D arrays, assigning values
The goal of this assignment is to write java programs in which the student is able to manipulate 2D arrays (creating 2D arrays, assigning values to the elements of the arrays, and defining and invoking methods that use 2D arrays as parameters). In this assignment, it is required to write a java class, Arrays2DTest, in which you have to create the following methods: public static int max(int[][] a) that returns the maximum value in the 2d parameter array a. public static int rowSum(int[][] a, int x) that returns the sum of the elements in Row x of a. public static int columnSum(int[][] a, int x) that returns the sum of the elements in Column x of a (careful with rows of different lengths!). public static int[] allRowSums(int[][] a) that calculates the row sum for every row and returns each of the values in an array. Index i of the return array contains the sum of elements in row i. public static boolean isRowMagic(int[][] a) that checks if the array is row-magic (this means that every row has the same row sum). public static boolean isColumnMagic(int[][] a) that checks if the array is column-magic (this means that every column has the same column sum). public static boolean isSquare(int[][] a) that checks if the array is square (i.e. every row has the same length as a itself). public static boolean isMagic(int[][] a) that checks if the array is a magic square. This means that it must be square, and that all row sums, all column sums, and the two diagonal-sums must all be equal. A main method, in which you do the following: a) Create one or two 2D arrays of integers. b) Invoke the previous methods to print out the sum per row and per column, and to find out if the array is magic.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
