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

2. 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. [2*5=10 Marks] The expected output is:Current Balance: $500Depositing $200...New Balance: $700Withdrawing $100...New Balance: $600java.lang.Exception: Insufficient Funds! Your balance is only $600.at BankAccount.withdraw(BankAccount.java:23)at Main.main(Main.java:18) Java Code:// Custom Exception classclass InsufficientFundsException extends Exception { public InsufficientFundsException(String message){ super(message); }} class BankAccount { private double balance; public BankAccount(double balance){ this.balance = balance; } public void deposit(double amount){ balance +=/*___MISSING CODE (A)___*/; System.out.println("Depositing $"+ amount +"..."); System.out.println("New Balance: $"+ balance); } public void withdraw(double amount) throws InsufficientFundsException { if (amount >/*___MISSING CODE (B)___*/){ throw new /*___MISSING CODE (C)___*/; } balance -= amount; System.out.println("Withdrawing $"+ amount +"..."); System.out.println("New Balance: $"+ balance); } public double getBalance(){ return /*___MISSING CODE (D)___*/; }} public class Main { public static void main(String[] args){ BankAccount account = new /*___MISSING CODE (E)___*/; System.out.println("Current Balance: $"+ account.getBalance()); account.deposit(200); try { account.withdraw(100); account.withdraw(700); // This will cause an exception } catch (InsufficientFundsException e){ e.printStackTrace(); }}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!