import java.util.Scanner; public class BankingApp { static class Account { private String accountNumber; private double balance; // Constructor to initialize account number and balance public Account(String accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } // Method to withdraw an amount from the account public void withdraw(double amount) throws IllegalArgumentException { if (amount < 0) { throw new IllegalArgumentException("Withdrawal amount cannot be negative."); } if (amount > balance) { throw new IllegalArgumentException("Insufficient funds."); } balance -= amount; // Deduct the amount from the balance } // Method to get the current balance public double getBalance() { return balance; } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Create an instance of Account Account account = new Account("123456789", 500.00); // Example account with initial balance System.out.print("Enter amount to withdraw: "); double amount = scanner.nextDouble(); try { account.withdraw(amount); // Attempt to withdraw the specified amount System.out.println("Withdrawal successful! New balance: " + account.getBalance()); } catch (IllegalArgumentException e) { System.out.println("Error: " + e.getMessage()); // Print error message for exceptions } finally { scanner.close(); // Close the scanner resource } } }