import java.util.*;
public class GradeProgram
{
public static void main(String[]args)
{
// Declare variables
double average=0;
int score1=0;
int score2=0;
int score3=0;
int score4=0;
int score5=0;
char grade1;
char grade2;
char grade3;
char grade4;
char grade5;
// Get the scores from the user
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the first score");
score1 = keyboard.nextInt();
System.out.println("Enter the second score");
score2 = keyboard.nextInt();
System.out.println("Enter the third score");
score3 = keyboard.nextInt();
System.out.println("Enter the fourth score");
score4 = keyboard.nextInt();
System.out.println("Enter the fifth score");
score5 = keyboard.nextInt();
// Call calcAverage method
average = calcAverage(score1, score2, score3, score4, score5);
//Display the average
System.out.println("The average is " + average);
// Call determineGrade method
grade1 = determineGrade(score1, score2, score3, score4, score5);
grade2 = determineGrade(score1, score2, score3, score4, score5);
grade3 = determineGrade(score1, score2, score3, score4, score5);
grade4 = determineGrade(score1, score2, score3, score4, score5);
grade5 = determineGrade(score1, score2, score3, score4, score5);
// Display the letter grades
System.out.println("Score " + "Grade");
System.out.println(score1 + " " + grade1);
System.out.println(score2 + " " + grade2);
System.out.println(score3 + " " + grade3);
System.out.println(score4 + " " + grade4);
System.out.println(score5 + " " + grade5);
}
// Calculates average of test scores
public static double calcAverage (int score1, int score2, int score3,
int score4, int score5)
{
// Calculate average
int total=0;
double average=0;
total = score1 + score2 + score3 + score4 + score5;
average = total / 5;
// Return average to main program
return average;
}
// Returns letter grade for test score
public static char determineGrade (int score1, int score2, int score3,
int score4, int score5)
{
// Declare variables to hold grades in
char grade1;
char grade2;
char grade3;
char grade4;
char grade5;
// Determines grade of first score
if (score1>=90 && score1<=100)
{ grade1 = 'A'; }
else if (score1>=80 && score1<90)
{ grade1 = 'B'; }
else if (score1>=70 && score1<80)
{ grade1 = 'C'; }
else if (score1>=60 && score1<70)
{ grade1 = 'D'; }
else
{ grade1 = 'F'; }
// Determines grade of second score
if (score2>=90 && score2<=100)
{ grade2 = 'A'; }
else if (score2>=80 && score2<90)
{ grade2 = 'B'; }
else if (score2>=70 && score2<80)
{ grade2 = 'C'; }
else if (score2>=60 && score2<70)
{ grade2 = 'D'; }
else
{ grade2 = 'F'; }
// Determines grade of third score
if (score3>=90 && score3<=100)
{ grade3 = 'A'; }
else if (score3>=80 && score3<90)
{ grade3 = 'B'; }
else if (score3>=70 && score3<80)
{ grade3 = 'C'; }
else if (score3>=60 && score3<70)
{ grade3 = 'D'; }
else
{ grade3 = 'F'; }
// Determines grade of fourth score
if (score4>=90 && score4<=100)
{ grade4 = 'A'; }
else if (score4>=80 && score4<90)
{ grade4 = 'B'; }
else if (score4>=70 && score4<80)
{ grade4 = 'C'; }
else if (score4>=60 && score4<70)
{ grade4 = 'D'; }
else
{ grade4 = 'F'; }
// Determines grade of fifth score
if (score5>=90 && score5<=100)
{ grade5 = 'A'; }
else if (score5>=80 && score5<90)
{ grade5 = 'B'; }
else if (score5>=70 && score5<80)
{ grade5 = 'C'; }
else if (score5>=60 && score5<70)
{ grade5 = 'D'; }
else
{ grade5 = 'F'; }
// Returns grades of tests
return grade1;
return grade2;
return grade3;
return grade4;
return grade5;
}
}