Code a Java utility class called SquareMatrix that has static methods which work
ID: 3531237 • Letter: C
Question
Code a Java utility class called SquareMatrix that has static methods which work on a given squared matrix. The
methods signatures are given below:
? Public static void displayMatrix(int[][] matrix);
Receives a two dimensional integer array and displays its contents in a formatted 2-D of rows and columns.
? public static int[] tenSums(int[][] matrix);
Receives a two dimensional integer array and returns a one dimensional integer array having the following
summations as it elements in the same order given below:
sum[0]: Sum of the element on the main diagonal.
sum[1]: Sum of the element on the secondary diagonal.
sum[2]: Sum of the elements above the main diagonal.
sum[3]: Sum of the elements below the main diagonal.
sum[4]: Sum of the elements above the secondary diagonal.
sum[5]: Sum of the elements below the secondary diagonal.
sum[6]: Sum of the elements above the main diagonal and above the secondary diagonal.
sum[7]: Sum of the elements below the main diagonal and below the secondary diagonal.
sum[8]: Sum of the elements below the main diagonal and above the secondary diagonal.
sum[9]: Sum of the elements above the main diagonal and below the secondary diagonal.
? public static double[] tenAverages(int[][] matrix);
Receives a two dimensional integer array and returns a one dimensional double array having the averages of
the elements in the ten sets above in the same order. This method should ,make use of the previously coded
method tenSums.
? public static double[] tenAverages(int[] sum, int size);
Receives an integer representing the number of rows in the original square matrix, and a one dimensional
integer array representing the ten sums of the ten sets identified earlier in the same order. You can this of
the sum matrix being the result found using the tenSums method in earlier step. The method tenAverages
should return the ten averages of the ten areas in a double one dimensional array.
? public static void mirrorOnMainDiagonal(int[][] matrix);
Receives a two dimensional integer array and it mirrors the original matrix on the main diagonal. In other
words you need to think of the main diagonal as a mirror for the element who will change place by swapping
based on reflection in the mirror. Or think of folding around the main diagonal for replacement of items
(exchange of places).
? public static void mirrorOnSecondaryDiagonal(int[][] matrix);
Receives a two dimensional integer array and it mirrors the original matrix on the secondary diagonal. In
other words you need to think of the secondary diagonal as a mirror for the element who will change place
by swapping based on reflection in the mirror. Or think of folding around the secondary diagonal for
replacement of items (exchange of places).
? public static void mirrorOnMiddleVertical(int[][] matrix);
Receives a two dimensional integer array and it mirrors the original matrix on the middle vertically. In other
words you need to think of the vertical middle as a mirror for the element who will change place by
swapping based on reflection in the mirror. Or think of folding around the middle vertically for replacement
of items (exchange of places).
? public static void mirrorOnMiddleHorizontal(int[][] matrix);
Receives a two dimensional integer array and it mirrors the original matrix on the middle horizontally. In
other words you need to think of the middle horizontally as a mirror for the element who will change place
by swapping based on reflection in the mirror. Or think of folding around the middle horizontally for
replacement of items (exchange of places).
2. Enforce in coding that the class SquareMatrix cannot be instantiated (cannot create objects from it), neither it
can be extended (cannot use it to build more extended form of it).
3. Code a Java testing class called TestSquareMatrix that does the following:
? creates a two dimensional array of size between 4by4 and 15by15 that is a randomly generated, i.e., the
size.
? Then fills up the array randomly with numbers from 0 up to that size, i.e., if the array is 10byto then the
elements should be from 0 to 99 randomly placed in the array.
? Displays the array on screen by calling the method displayMatrix of the class SquareMatrix
? Calls the all the methods of the class SquareMatrix and display the results after each call.
Explanation / Answer
Hey, please rate with 5 stars :)
Here is everything that you want.
http://www.ini.uzh.ch/~fred/java/Matrix.java
Cheers!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.