Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that creates a two-dimensional array initialized with test data.

ID: 3635013 • Letter: W

Question

Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type of your choice. The program should also have the following methods:

º getTotal. This method should accept a 2D array as its argument and rturn the total of the values in the array.
º getAverage. This method should accept a 2D array as its argument and return the average of the values in the aray.
º getRowTotal. This method should accept a 2D array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in he array. The method should return the total of the values in the specified row.
º getColumtTotal. This method should accept a 2D array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in he array. The method should return the total of the values in the specified column.
º getHighestInRow. This method should accept a 2D array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in he array. The method should return the highest value in the specified row of the array.
º getLowestInRow. This method should accept a 2D array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in he array. The method should return the lowest value in the specified row of the array.

Explanation / Answer

Dear, Here is the code import java.io.*; class ArrayDemo { //main function public static void main(String []arg) { int [][]list={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; //Function call and display data returned System.out.println("Total:"+getTotal(list)); System.out.println("Average:"+getAverage(list)); System.out.println("Row 2 value:" +getRowTotal(list,2)); System.out.println("Column 3 Total :" +getColumnTotal(list,3)); System.out.println("Highest value in row 1 is :" +getHighest(list,1)); System.out.println("Lowest value in row 2 is :" +getLowest(list,2)); //Exit program System.exit(0); }//end main //returns sum of elements of array public static int getTotal(int [][]numbers) { int tot=0; //Loop repeats untill list ends for(int row=0;row
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote