93.6k views
1 vote
Create a method called letterGrade that will pass the student's average grade as a parameter and return a letter grade (char). Once passed, use an if..else if structure to determine whether the student has an A, B, C, D, or F. Return that letter grade. Use the standard grade scale: 90-100 (A), 80-89 (B), 70-79 (C), 60-69 (D), 0-59 (F).

1 Answer

3 votes

Answer:

The method in Java is as follows:

public static char letterGrade(int average){

char grade =' ';

if(average>= 90 && average <=100){ grade ='A'; }

else if(average>= 80 && average <=89){ grade ='B'; }

else if(average>= 70 && average <=79){ grade ='C'; }

else if(average>= 60 && average <=69){ grade ='D'; }

else if(average>= 0 && average <=59){ grade ='F'; }

return grade;

}

Step-by-step explanation:

This defines the method

public static char letterGrade(int average){

This initializes the grade to a blank

char grade =' ';

If average is between 90 and 100 (inclusive), grade is A

if(average>= 90 && average <=100){ grade ='A'; }

If average is between 80 and 89 (inclusive), grade is B

else if(average>= 80 && average <=89){ grade ='B'; }

If average is between 70 and 79 (inclusive), grade is C

else if(average>= 70 && average <=79){ grade ='C'; }

If average is between 60 and 69 (inclusive), grade is D

else if(average>= 60 && average <=69){ grade ='D'; }

If average is between 0 and 59 (inclusive), grade is F

else if(average>= 0 && average <=59){ grade ='F'; }

This returns the grade

return grade;

}

User Grim
by
3.3k points