← Back to Miscellaneous
Question 216
Custom RuntimeException
Custom RuntimeException
Build a stock-checking system: 1. Create a classOutOfStockExceptionthat extendsRuntimeException. Its constructor takes aStringitem name and passes"Out of stock: " + itemtosuper. 2. Write a methodcheckStock(String item, int qty)that throwsOutOfStockExceptionifqtyis 0. 3. Inmain, read an item name and quantity. CallcheckStock, print"In stock"if no exception, or printe.getMessage()if caught. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain'apples 0\n'.
Expected Output:
Out of stock: apples
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.