In: Computer Science
Write a method with the following header:
public static char calculateLetterGrade(int grade, int totalMarks)
This method calculates grade/totalMarks and returns a letter grade based on the following scale:
0-50 = F
51-60 = D
61-70 = C
71-80 = B
81-100 = A
Code:
class Main
{
public static char calculateLetterGrade(int grade, int totalMarks) //it will return grade based on total marks
{
if(totalMarks>=81 && totalMarks<=100) //if marks in between of 81-100 then grade is A
{
return 'A';
}
else if(totalMarks>=71 && totalMarks<=80) //if marks in between of 71-80 then grade is B
{
return 'B';
}
else if(totalMarks>=61 && totalMarks<=70) //if marks in between of 61-70 then grade is C
{
return 'C';
}
else if(totalMarks>=51 && totalMarks<=60) //if marks in between of 51-60 then grade is D
{
return 'D';
}
else if(totalMarks>=0 && totalMarks<=50) //if marks in between of 0-50 then grade is F
{
return 'F';
}
return '0';
}
public static void main(String args[])
{
System.out.println("Grade of marks 90 is: "+calculateLetterGrade(1,90));
System.out.println("Grade of marks 80 is: "+calculateLetterGrade(2,80));
System.out.println("Grade of marks 64 is: "+calculateLetterGrade(3,64));
System.out.println("Grade of marks 57 is: "+calculateLetterGrade(4,57));
System.out.println("Grade of marks 45 is: "+calculateLetterGrade(5,45));
}
}
Output:
.