Answer:
import java.util.ArrayList;
import java.util.Scanner;
public class StudentGrade {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> nameList = new ArrayList<String>();
double scores[][] = new double[5][4];
for(int i=0; i<scores.length; i++){
System.out.println("Enter Student "+(i+1)+" Name: ");
nameList.add(scan.nextLine());
System.out.println("Enter Student "+(i+1)+" scores: ");
for(int j=0; j<scores[i].length; j++){
scores[i][j] = scan.nextDouble();
}
scan.nextLine();
}
for(int i=0; i<nameList.size(); i++){
System.out.println("Student "+(i+1)+" Information: ");
System.out.println("Student Name: "+getName(i, nameList));
double average = getAverage(scores, i);
System.out.println("Student Average: "+average);
System.out.println("Student Grade: "+getGrade(average));
}
}
public static char getGrade(double average){
char grades[] = {'A','B','C','D','F'};
if(average >=90 && average<=100){
return grades[0];
}
else if(average >=80 && average<90){
return grades[1];
}
else if(average >=70 && average<80){
return grades[2];
}
else if(average >=60 && average<70){
return grades[3];
}
else {
return grades[4];
}
}
public static double getAverage(double scores[][], int index){
double average = 0;
double sum = 0;
for(int i=0; i<scores[index].length; i++){
sum = sum + scores[index][i];
}
average = sum / 4;
return average;
}
public static String getName(int index, ArrayList<String> namelist){
return namelist.get(index);
}
}