Answer:
public class Grade {
public static void main (String [] args) {
int sum = 0, avg = 0;
char grade = 'x';
Scanner input = new Scanner(System.in);
System.out.print("Enter the test scores: ");
for(int i=1; i<=3; i++) {
int testScore = input.nextInt();
sum += testScore;
}
avg = sum/3;
if(avg >= 90) {
grade = 'A';
}
else if(avg>= 80 && avg < 90) {
grade = 'B';
}
else if(avg>= 70 && avg < 80) {
grade = 'C';
}
else if(avg>= 60 && avg < 70) {
System.out.print("Enter the number of homeworks turned in: ");
int homeworksTurnedIn = input.nextInt();
System.out.print("Enter the total number of homeworks: ");
int totalHomeworks = input.nextInt();
if((homeworksTurnedIn / (double)totalHomeworks) > 0.8) {
grade = 'D';
}
else
grade = 'F';
}
else if(avg < 60) {
grade = 'F';
}
System.out.println("Your grade is: " + grade);
}
}
Explanation:
- Initialize the variables
- Ask the user for the test scores
- Inside the for loop, calculate the <em>sum</em> of the test scores
- Then, find the <em>average</em> of the scores
- Depending on the <em>average</em>, print the <em>grade</em>