Code:
import [Link];
import [Link];
class Account {
private int custID;
private String custName;
private double balance;
private static double annualInterestRate = 0.03; // 3% annual interest rate
public Account(int custID, String custName, double balance) {
[Link] = custID;
[Link] = custName;
[Link] = balance;
}
public int getCustID() {
return custID;
}
public String getCustName() {
return custName;
}
public double getBalance() {
return balance;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (amount <= balance) {
balance -= amount;
} else {
[Link]("Insufficient balance.");
}
}
public void applyInterest() {
balance += balance * annualInterestRate;
}
public static void setAnnualInterestRate(double rate) {
annualInterestRate = rate;
}
}
public class AccountDriver {
public static void main(String[] args) throws Exception{
Scanner scanner = new Scanner([Link]);
ArrayList<Account> accounts = new ArrayList<>();
while (true) {
[Link]("Menu:");
[Link]("1. Add account");
[Link]("2. Display individual account");
[Link]("3. Display all accounts");
[Link]("4. Deposit to individual account");
[Link]("5. Withdraw from individual account");
[Link]("6. Financial Year ending");
[Link]("7. Exit");
[Link]("Enter your choice: ");
int choice = [Link]();
[Link](); // Consume the newline character
switch (choice) {
case 1:
[Link]("Enter customer ID: ");
int custID = [Link]();
[Link](); // Consume the newline character
[Link]("Enter customer name: ");
String custName = [Link]();
[Link]("Enter initial balance: ");
double initialBalance = [Link]();
Account account = new Account(custID, custName,
initialBalance);
[Link](account);
[Link]("Account added successfully!");
break;
case 2:
[Link]("Enter customer ID to display account: ");
int displayCustID = [Link]();
displayIndividualAccount(accounts, displayCustID);
break;
case 3:
displayAllAccounts(accounts);
break;
case 4:
[Link]("Enter customer ID for deposit: ");
int depositCustID = [Link]();
[Link]("Enter deposit amount: ");
double depositAmount = [Link]();
depositToIndividualAccount(accounts, depositCustID,
depositAmount);
break;
case 5:
[Link]("Enter customer ID for withdrawal: ");
int withdrawCustID = [Link]();
[Link]("Enter withdrawal amount: ");
double withdrawAmount = [Link]();
withdrawFromIndividualAccount(accounts, withdrawCustID,
withdrawAmount);
break;
case 6:
for (Account acc : accounts) {
[Link]();
}
[Link]("Interest applied for all accounts.");
break;
case 7:
[Link]("Exiting the program.");
[Link]();
[Link](0);
break;
default:
[Link]("Invalid choice. Please try again.");
}
}
}
public static void displayIndividualAccount(ArrayList<Account> accounts, int
custID) {
for (Account account : accounts) {
if ([Link]() == custID) {
[Link]("Customer ID: " + [Link]());
[Link]("Customer Name: " + [Link]());
[Link]("Balance: " + [Link]());
return;
}
}
[Link]("Account not found with Customer ID: " + custID);
}
public static void displayAllAccounts(ArrayList<Account> accounts) {
[Link]("All Accounts:");
for (Account account : accounts) {
[Link]("Customer ID: " + [Link]());
[Link]("Customer Name: " + [Link]());
[Link]("Balance: " + [Link]());
[Link]();
}
}
public static void depositToIndividualAccount(ArrayList<Account> accounts,
int custID, double amount) {
for (Account account : accounts) {
if ([Link]() == custID) {
[Link](amount);
[Link]("Deposit successful. New balance: " +
[Link]());
return;
}
}
[Link]("Account not found with Customer ID: " + custID);
}
public static void withdrawFromIndividualAccount(ArrayList<Account>
accounts, int custID, double amount) {
for (Account account : accounts) {
if ([Link]() == custID) {
[Link](amount);
[Link]("Withdrawal successful. New balance: " +
[Link]());
return;
}
}
[Link]("Account not found with Customer ID: " + custID);
}
}
Screenshot: