Astitwo Java Code
Astitwo Java Code
Astitwo Java Code
import java.util.ArrayList;
import java.util.Scanner;
class Account {
private int custID;
private String custName;
private double balance;
private static double annualInterestRate = 0.03; // 3% annual interest rate
while (true) {
System.out.println("Menu:");
System.out.println("1. Add account");
System.out.println("2. Display individual account");
System.out.println("3. Display all accounts");
System.out.println("4. Deposit to individual account");
System.out.println("5. Withdraw from individual account");
System.out.println("6. Financial Year ending");
System.out.println("7. Exit");
switch (choice) {
case 1:
System.out.print("Enter customer ID: ");
int custID = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
case 2:
System.out.print("Enter customer ID to display account: ");
int displayCustID = scanner.nextInt();
displayIndividualAccount(accounts, displayCustID);
break;
case 3:
displayAllAccounts(accounts);
break;
case 4:
System.out.print("Enter customer ID for deposit: ");
int depositCustID = scanner.nextInt();
System.out.print("Enter deposit amount: ");
double depositAmount = scanner.nextDouble();
depositToIndividualAccount(accounts, depositCustID,
depositAmount);
break;
case 5:
System.out.print("Enter customer ID for withdrawal: ");
int withdrawCustID = scanner.nextInt();
System.out.print("Enter withdrawal amount: ");
double withdrawAmount = scanner.nextDouble();
withdrawFromIndividualAccount(accounts, withdrawCustID,
withdrawAmount);
break;
case 6:
for (Account acc : accounts) {
acc.applyInterest();
}
System.out.println("Interest applied for all accounts.");
break;
case 7:
System.out.println("Exiting the program.");
scanner.close();
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
public static void displayIndividualAccount(ArrayList<Account> accounts, int
custID) {
for (Account account : accounts) {
if (account.getCustID() == custID) {
System.out.println("Customer ID: " + account.getCustID());
System.out.println("Customer Name: " + account.getCustName());
System.out.println("Balance: " + account.getBalance());
return;
}
}
System.out.println("Account not found with Customer ID: " + custID);
}
Screenshot: