CJCoding With Joseph
15free / daySign inCreate account

Create a checked exception and use it: 1. Define InsufficientFundsException that extends Exception with a constructor that accepts a message string. 2. Write withdraw(double balance, double amount) throws InsufficientFundsException — throw the exception with message "Not enough funds" if amount > balance. 3. In main, read balance and amount. Call withdraw, print "Withdrawal successful" or "Error: " + e.getMessage() if caught.

Because InsufficientFundsException extends Exception (not RuntimeException), withdraw must declare throws.

⚠️ AUTO-INPUT MODE: The input stream will automatically contain a balance and an amount, for example '50.0 100.0\n'. Your code is also run with a balance that covers the amount, so both messages must work.

Expected output

Error: Not enough funds

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
Miscellaneous
Auto-input
50.0 100.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.