CJCoding With Joseph
15free / daySign inCreate account

Custom RuntimeException

Build 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 — print one after the last line.

Hints4 available
Topics:
Miscellaneous
📥 Auto-Input:
apples 0\n
This input is automatically fed to your program's stdin
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.