← Back to Miscellaneous
Question 221
Validate Score with Custom Exception
Validate Score with Custom Exception
Build a score validation system from scratch: 1. CreateInvalidScoreExceptionthat extendsRuntimeExceptionwith a message constructor. 2. WritevalidateScore(int score)that throwsInvalidScoreExceptionwith the message"Score out of range: " + scoreif score is less than 0 or greater than 100. 3. Inmain, read a score, callvalidateScore, print"Score accepted"if valid, or printe.getMessage()if caught. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain'150\n'.
Expected Output:
Score out of range: 150
Topics:
Miscellaneous
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.