import [Link].
Scanner;
public class BankSystem {
public static void main(String[] args) {
Bank bank = new Bank();
Scanner scanner = new Scanner([Link]);
boolean exit = false;
while (!exit) {
[Link]("\nBanking System Menu:");
[Link]("1. Create Account");
[Link]("2. Deposit Money");
[Link]("3. Withdraw Money");
[Link]("4. Check Balance");
[Link]("5. Exit");
[Link]("Choose an option: ");
int choice = [Link]();
[Link](); // Consume newline
switch (choice) {
case 1:
[Link]("Enter account ID: ");
String accountId = [Link]();
[Link](accountId);
break;
case 2:
[Link]("Enter account ID: ");
accountId = [Link]();
[Link]("Enter amount to deposit: ");
double depositAmount = [Link]();
try {
[Link](accountId, depositAmount);
} catch (Exception e) {
[Link]([Link]());
}
break;
case 3:
[Link]("Enter account ID: ");
accountId = [Link]();
[Link]("Enter amount to withdraw: ");
double withdrawAmount = [Link]();
try {
[Link](accountId, withdrawAmount);
} catch (Exception e) {
[Link]([Link]());
}
break;
case 4:
[Link]("Enter account ID: ");
accountId = [Link]();
try {
double balance = [Link](accountId);
[Link]("Balance: " + balance);
} catch (Exception e) {
[Link]([Link]());
}
break;
case 5:
exit = true;
break;
default:
[Link]("Invalid option. Please try again.");
}
}
[Link]();
}
}
class Bank {
private static final int MAX_ACCOUNTS = 100;
private Account[] accounts;
private int accountCount;
public Bank() {
accounts = new Account[MAX_ACCOUNTS];
accountCount = 0;
}
public void createAccount(String accountId) {
if (findAccount(accountId) != null) {
[Link]("Account with ID " + accountId + " already
exists.");
} else if (accountCount >= MAX_ACCOUNTS) {
[Link]("Cannot create more accounts. Maximum limit
reached.");
} else {
accounts[accountCount++] = new Account(accountId);
[Link]("Account created successfully.");
}
}
public void deposit(String accountId, double amount) throws Exception {
Account account = findAccount(accountId);
if (account == null) {
throw new Exception("Account with ID " + accountId + " does not
exist.");
}
if (amount <= 0) {
throw new Exception("Deposit amount must be positive.");
}
[Link](amount);
[Link]("Deposited " + amount + " to account " + accountId);
}
public void withdraw(String accountId, double amount) throws Exception {
Account account = findAccount(accountId);
if (account == null) {
throw new Exception("Account with ID " + accountId + " does not
exist.");
}
if (amount <= 0) {
throw new Exception("Withdrawal amount must be positive.");
}
if (amount > [Link]()) {
throw new Exception("Insufficient balance.");
}
[Link](amount);
[Link]("Withdrew " + amount + " from account " + accountId);
}
public double checkBalance(String accountId) throws Exception {
Account account = findAccount(accountId);
if (account == null) {
throw new Exception("Account with ID " + accountId + " does not
exist.");
}
return [Link]();
}
private Account findAccount(String accountId) {
for (int i = 0; i < accountCount; i++) {
if (accounts[i].getAccountId().equals(accountId)) {
return accounts[i];
}
}
return null;
}
}
class Account {
private String accountId;
private double balance;
public Account(String accountId) {
[Link] = accountId;
[Link] = 0.0;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
balance -= amount;
}
public double getBalance() {
return balance;
}
public String getAccountId() {
return accountId;
}
}