Question: Can someone please help me with finding the average per the following requirement? Program 4: Design (pseudocode) and implement (source code) a program (name it
Can someone please help me with finding the average per the following requirement?
Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a two-dimensional array of type integer as a parameter and prints out the class highest grade, the class lowest grade, and class average grade as shown below.
import java.util.*;
public class MinMaxAvg {
public static void main(String[] args) { Random rand = new Random(); int [][] grades = new int [4][4]; System.out.println("Array Grades: "); for (int i = 0; i < grades.length; i++) { for (int j = 0; j < grades[i].length; j++) { grades[i][j] = rand.nextInt(100); System.out.print("\t" + grades[i][j] + ""); } // ENDFOR System.out.println(); } // ENDFOR minMaxAvg(grades); System.out.println(); } // END METHOD Main public static void minMaxAvg(int [][] grades) { double total = 0; double average = 0; int max = 0; int min = 100; for (int row = 0; row < grades.length; row++) { for (int column = 0; column < grades[row].length; column++) { if (grades[row][column] > max) { max = grades[row][column]; } if (grades[row][column] < min) { min = grades[row][column]; } } // ENDFOR for (int i = 0; i < grades.length; i++) { for (int j = 0; j < grades[i].length; j++) { total = (total + grades[i][j]); average = (total / grades.length); } // ENDFOR } } System.out.println(); System.out.println("Highest Grade: " + max); System.out.println("Lowest Grade: " + min); System.out.printf("Class Average: " + "%.2f",average); } // END METHOD
} // END class MinMaxAvg
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
