27.4k views
4 votes
Write a function that when passed a grade average will return the letter-grade based on a 90/80/70/60 grade scale.

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Java and creates a function called letterGrade. This function takes an int parameter for the number grade given. Then it takes that number grade and puts it through a switch function which will compare the number to the correct case and output the corresponding letter grade.

public static char letterGrade (int numberGrade) {

char grade = ' ';

switch (numberGrade) {

case 90:

grade = 'A';

break;

case 80:

grade = 'B';

break;

case 70:

grade = 'C';

break;

case 60:

grade = 'D';

break;

default:

System.out.println("Grade must be 90/80/70/60");

}

return grade;

}

User Mythox
by
5.3k points