Question: 2 . Consider the code snippet below. This code represents a basic banking application where a user has a checking account. The user can deposit
Consider the code snippet below. This code represents a basic banking application where a user has a checking account. The user can deposit and withdraw money from the account. The system should not allow the user to withdraw more money than they have in the account. If a user tries to do so the system should throw an InsufficientFundsException.Fill in the missing codes to make the program work as described above. Marks The expected output is:Current Balance: $Depositing $New Balance: $Withdrawing $New Balance: $java.lang.Exception: Insufficient Funds! Your balance is only $at BankAccount.withdrawBankAccountjava:at Main.mainMainjava: Java Code: Custom Exception classclass InsufficientFundsException extends Exception public InsufficientFundsExceptionString message supermessage; class BankAccount private double balance; public BankAccountdouble balance this.balance balance; public void depositdouble amount balance MISSING CODE A; System.out.printlnDepositing $ amount ; System.out.printlnNew Balance: $ balance; public void withdrawdouble amount throws InsufficientFundsException if amount MISSING CODE B throw new MISSING CODE C; balance amount; System.out.printlnWithdrawing $ amount ; System.out.printlnNew Balance: $ balance; public double getBalance return MISSING CODE D; public class Main public static void mainString args BankAccount account new MISSING CODE E; System.out.printlnCurrent Balance: $ account.getBalance; account.deposit; try account.withdraw; account.withdraw; This will cause an exception catch InsufficientFundsException e eprintStackTrace;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
