Loading...
Loading...
Loading...
A school marks every paper out of 100. The pass mark and the maximum belong to the grading rules, so they are constants in an interface.
Write an interface Grading with int PASS = 35, int MAX = 100 and String grade(int marks). A class SchoolGrading returns A for 90 and above, B for 75 to 89, PASS for 35 to 74 and FAIL below 35. Marks outside 0 to MAX are INVALID.
marks -> grade, then PASSED p OF v where v counts the valid marks and p the ones at or above PASS.Example
Input
5 92 40 20 76 101
Output
92 -> A 40 -> PASS 20 -> FAIL 76 -> B 101 -> INVALID PASSED 3 OF 4
101 is invalid, so 4 marks count and 3 of them pass.
Try the problem first. Open one hint at a time.
Inside a class that implements Grading, the constants are used by their plain names: PASS, MAX.
Check the invalid case first, then the grades from the top down.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor