Assignment 4: Code
Assignment 4: Code
23104B0081
EXTC B
ASSIGNMENT 4
You are tasked with writing a Java program to simulate a simple bank account system. The
program should handle exceptions related to common banking operations such as deposits,
withdrawals, and balance inquiries. The system should allow a user to perform operations on
a bank account, with proper exception handling for scenarios such as insufficient balance,
invalid account number, and invalid deposit amounts.
CODE:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
super(message);
super(message);
super(message);
// BankAccount class
class BankAccount {
this.accountNumber = accountNumber;
this.balance = 0.0;
return accountNumber;
return balance;
if (amount <= 0) {
throw new InvalidDepositAmountException("Deposit amount must be greater than zero.");
}
balance += amount;
}
public void withdraw(double amount) throws InsufficientBalanceException {
}
balance -= amount;
System.out.println("Withdrew: " + amount);
class Bank {
throw new InvalidAccountException("Account number " + accountNumber + " does not exist.");
return account;
// Main class
while (true) {
switch (choice) {
case 1:
System.out.print("Enter account number: ");
case 2:
case 3:
}
break;
case 4:
} catch (InvalidAccountException e) {
break;
case 5:
System.out.println("Exiting...");
scanner.close();
return;
default:
}
}