-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankApplication.java
More file actions
103 lines (89 loc) · 3.33 KB
/
Copy pathBankApplication.java
File metadata and controls
103 lines (89 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package project;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
public class
{
private List<Customer> customers = new ArrayList<>();
private List<Account> accounts = new ArrayList<>();
private List<Transaction> transactions = new ArrayList<>();
private List<Loan> loans = new ArrayList<>();
private Scanner scanner = new Scanner(System.in);
public void run() {
// Create a customer
Customer customer = new Customer();
customer.setName("John Doe");
customer.setAddress("123 Main St");
customer.setPhoneNumber("123-456-7890");
customer.setEmail("[email protected]");
customer.setDateOfBirth(LocalDate.of(1990, 1, 1));
// Add customer to the list
customers.add(customer);
// Create an account
Account account = new Account();
account.setAccountNumber("123456789");
account.setBalance(1000.00);
// Add account to the list
accounts.add(account);
// Perform user-driven account activities
userMenu(account);
// Print out the lists
System.out.println("Customers: " + customers);
System.out.println("Accounts: " + accounts);
System.out.println("Transactions: " + transactions);
System.out.println("Loans: " + loans);
}
// User menu for account activities
private void userMenu(Account account) {
boolean exit = false;
while (!exit) {
System.out.println("\nChoose an option:");
System.out.println("1. Credit Account");
System.out.println("2. Debit Account");
System.out.println("3. Display Balance");
System.out.println("4. Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
creditAccount(account);
break;
case 2:
debitAccount(account);
break;
case 3:
account.displayBalance();
break;
case 4:
exit = true;
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
// Method to credit the account
private void creditAccount(Account account) {
System.out.print("Enter amount to credit: ");
double amount = scanner.nextDouble();
account.credit(amount);
addTransaction(amount, "credit");
}
// Method to debit the account
private void debitAccount(Account account) {
System.out.print("Enter amount to debit: ");
double amount = scanner.nextDouble();
account.debit(amount);
addTransaction(amount, "debit");
}
// Add a transaction to the list
private void addTransaction(double amount, String type) {
Transaction transaction = new Transaction();
transaction.setTransactionId(UUID.randomUUID().toString());
transaction.setAmount(amount);
transaction.setTransactionDate(LocalDate.now());
transaction.setType(type);
transactions.add(transaction);
}
}