226k views
2 votes
Write a program that determines a student's letter grade. Allow the user to enter three test scores. The maximum score on each test is 100 points. Determine the letter grade from the average of the test scores, using the following: 90% or more A 80% or more, but less than 90% B 70% or more, but less than 80% C 60% or more, but less than 70% D or F, to be determined from additional information less than 60% F Only if the grade needs to be determined between D and F, allow the user to enter the number of homework assignments the student turned in, and the total number of homework assignments. If more than 80% of the homework assignments were turned in, the letter grade is D, otherwise F. Test it 4 times: 96 84 90 95 83 90 70 59 60 with 5 homework out of 6 turned in 73 58 65 with 8 homework out of 11 turned in Compute the results by hand and check your results.

User Gderaco
by
6.4k points

1 Answer

4 votes

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);

}

}

Step-by-step explanation:

- Initialize the variables

- Ask the user for the test scores

- Inside the for loop, calculate the sum of the test scores

- Then, find the average of the scores

- Depending on the average, print the grade

User Rayee Roded
by
5.9k points