Answer:
// Scanner class is imported so that the program can can user input
import java.util.Scanner;
// class Solution is defined
public class Solution {
//main method which begin program execution is defined
public static void main(String args[]) {
// Scanner object scan is defined to receive input fromkeyboard
Scanner scan = new Scanner(System.in);
// A prompt is display to the user asking for number of grade
System.out.println("How many grade do you want to enter");
// The user input is assigned to numOfGrade
int numOfGrade = scan.nextInt();
// An array of integer called gradeArray is declared
// it has numOfGrade as length
int[] gradeArray = new int[numOfGrade];
// for-loop that prompt the user to enter grade to fill the gradeArray
for(int i = 0; i < numOfGrade; i++){
System.out.println("Enter a grade: ");
int grade = scan.nextInt();
gradeArray[i] = grade;
}
// sun variable is declared and initialized to 0
int sum = 0;
// numOfFail is declared and initialized to 0
int numOfFail = 0;
// for-loop through the gradeArray that add all element
// it also increase the counter for numOfFail if grade is < 70
for(int j = 0; j < gradeArray.length; j++){
sum += gradeArray[j];
if (gradeArray[j] < 70){
numOfFail++;
}
}
// aveargeGrade is calculated
int averageGrade = (sum / numOfGrade);
// numOfFail is displayed to the user
System.out.println("Number of fail is: " + numOfFail);
// the averageGrade is also displayed.
System.out.println("Average grade is: " + averageGrade);
}
}
Step-by-step explanation:
The code is well commented and written in Java.