Custom RuntimeException
mediumQuestion 216Build a stock-checking system:
1. Create a class OutOfStockException that extends RuntimeException. Its constructor takes a String item name and passes "Out of stock: " + item to super.
2. Write a method checkStock(String item, int qty) that throws OutOfStockException if qty is 0.
3. In main, read an item name and quantity. Call checkStock, print "In stock" if no exception, or print e.getMessage() if caught.
⚠️ AUTO-INPUT MODE: The input stream will automatically contain 'apples 0\n'.
Expected output
Out of stock: apples= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Miscellaneous
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.