Answer:
import java.util.Scanner;
public class TestAveGrade
{
public static void main(String[] args) {
Scanner scanner = new Scanner( System.in );
double userScore1, userScore2, userScore3, userScore4, userScore5;
System.out.print ("Enter test grade for student1:");
userScore1 = scanner.nextDouble();
System.out.print ("Enter test grade for student2:");
userScore2 = scanner.nextDouble();
System.out.print ("Enter test grade for student3:");
userScore3 = scanner.nextDouble();
System.out.print ("Enter test grade for student4:");
userScore4 = scanner.nextDouble();
System.out.print ("Enter test grade for student5:");
userScore5 = scanner.nextDouble();
System.out.println("The letter grades are as follows:");
System.out.println("Student-1: " + determineGrade(userScore1));
System.out.println("Student-2: " + determineGrade(userScore2));
System.out.println("Student-3: " + determineGrade(userScore3));
System.out.println("Student-4: " + determineGrade(userScore4));
System.out.println("Student-5: " + determineGrade(userScore5));
System.out.printf("The average grade was: %.2f", calcAverage (userScore1, userScore2, userScore3, userScore4, userScore5));
}
public static double calcAverage(double userScore1, double userScore2, double userScore3, double userScore4, double userScore5){
double average;
average = (userScore1 +userScore2 +userScore3 +userScore4 +userScore5) /5;
return average;
}
public static String determineGrade(double testScore){
String letterGrade = " ";
if (testScore < 60){
letterGrade = "F";
}
else if (testScore <70) {
letterGrade = "D";
}
else if (testScore <80) {
letterGrade = "C";
}
else if (testScore <90) {
letterGrade = "B";
}
else if (testScore <100) {
letterGrade = "A";
}
return letterGrade;
}
}
Explanation:
Hi, I modified your code. Your methods work but you need to update the main.
Ask the user to enter five grades and store the values in different variables
Call the determineGrade method passing each grade as a parameter
Call the calcAverage method passing all the grades as parameter