...

/

Solution Review: Assign Grades to Students

Solution Review: Assign Grades to Students

Have a look at the solution to the 'Assign Grades to Students' challenge.

Rubric criteria

Solution

Press + to interact
class GradingSystem
{
public static void main(String args[])
{
System.out.println(assignGrades(75));
}
// Function assigning the grades
public static char assignGrades(double score)
{
if (score == 100)
{
System.out.println("Superb");
return 'A';
}
else if (score >= 90)
{
System.out.println("Excelent");
return 'A';
}
else if (score >= 80)
{
System.out.println("Very Good");
return 'B';
}
else if (score >= 70)
{
System.out.println("Good");
return 'C';
}
else if (score >= 60)
{
System.out.println("Work Hard");
return 'D';
}
else
{
System.out.println("Fail");
return 'F';
}
}
}

Rubric-wise explanation


Point 1:

Look at line 9. We declare the header of the assignGrades() function: public static char assignGrades(double score). We add the static keyword so that we can directly call this method in the main function without any instance.

Point 2, 3, 4:

  • Look at line 11. We add a condition next to an if keyword. If the score is equal to 100100, then we ...