-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
57 lines (47 loc) · 1.46 KB
/
Copy pathBank.java
File metadata and controls
57 lines (47 loc) · 1.46 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
import java.util.ArrayList;
class Bank {
private ArrayList<Account> accounts = new ArrayList<>();
public void createAccount(Account account){
accounts.add(account);
System.out.println("Account created successfully!");
}
public Account findAccount(int accountNumber){
for(Account ac : accounts){
if(ac.getAccountNumber() == accountNumber){
return ac;
}
}
return null;
}
public Account authenticateUser(int accountNumber, int pin){
Account account = findAccount(accountNumber);
if(account != null && account.authenticate(pin))
return account;
return null;
}
public void depositToAccount(int accountNumber, double amount){
Account account = findAccount(accountNumber);
if(account == null){
System.out.println("Account not found!");
return;
}
account.deposit(amount);
}
public void withdrawFromAccount(int accountNumber, double amount){
Account account = findAccount(accountNumber);
if(account == null){
System.out.println("Account not found!");
return;
}
account.withdraw(amount);
}
public void displayAllAccounts(){
if(accounts.isEmpty()){
System.out.println("No Accounts Available!");
return;
}
for(Account ac : accounts){
ac.display();
}
}
}