Loading...
Loading...
A teacher types marks for a test out of max. A mark below 0 or above max is a typing mistake and must be reported, not saved.
Write InvalidMarksException extends Exception and a class Test with void record(String name, int marks) throws InvalidMarksException. Test keeps the count, the total and the top scorer (the first one on a tie) of the valid marks.
SAVED name marks or REJECTED name: marks m not in 0 to max. Then AVERAGE a OF k (two decimals) and TOP name, or the single line NO VALID MARKS.Example
Input
100 4 Asha 78 Ravi 120 Meena 91 Kiran -5
Output
SAVED Asha 78 REJECTED Ravi: marks 120 not in 0 to 100 SAVED Meena 91 REJECTED Kiran: marks -5 not in 0 to 100 AVERAGE 84.50 OF 2 TOP Meena
Two typing mistakes; the average uses only 78 and 91.
Try the problem first. Open one hint at a time.
Because the exception extends Exception, it is checked: record must say throws InvalidMarksException, and main must catch it.
Throw before changing any field, so a rejected mark leaves the totals unchanged.
Divide the total by the count as double for the average.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor