-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
103 lines (77 loc) · 2.74 KB
/
Copy pathBank.java
File metadata and controls
103 lines (77 loc) · 2.74 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 Account;
import java.util.ArrayList;
import java.util.List;
public class Bank {
String bankName;
List<BankAccount> myAccountList;
public Bank(String bankName){
this.bankName = bankName;
myAccountList = new ArrayList<>();
}
public void createAccount(int pin,String name,String phoneNumber,int age){
BankAccount account = new BankAccount(pin,name,phoneNumber,age);
myAccountList.add(account);
}
public List<BankAccount> showAllAccount(){
return myAccountList;
}
public int getNoOfAccount(){
return myAccountList.size();
}
public BankAccount getAccount(String acctNumber){
for(BankAccount account : myAccountList){
if(account.getAccountNumber().equals(acctNumber)){
return account;
}
}
return null;
}
public boolean isExist(String accountNumber){
for(BankAccount account : myAccountList){
if(account.getAccountNumber().equals(accountNumber)){
return true;
}
}
return false;
}
public void depositAmount(String accountNumber,int amount){
BankAccount account = getAccount(accountNumber);
if(account == null){
throw new IllegalArgumentException("account number not found");
}
account.deposit(amount);
}
public int checkAccountBalance(String accountNumber,int pin){
BankAccount account = getAccount(accountNumber);
if(account == null){
throw new IllegalArgumentException("account number not found");
}
return account.checkBalance(pin);
}
public void withdrawAmount(String accountNumber,int amount,int pin){
BankAccount account = getAccount(accountNumber);
if(account == null){
throw new IllegalArgumentException("account number not found");
}
account.withdraw(amount,pin);
}
public void deleteAccount(String accountNumber){
BankAccount account = getAccount(accountNumber);
if(account == null){
throw new IllegalArgumentException("account number not found");
}
myAccountList.remove(account);
}
public void transfer(String fromAccount, int pin, String toAccount, int amount){
BankAccount accountOne = getAccount( fromAccount);
if(accountOne == null){
throw new IllegalArgumentException("account number not found");
}
BankAccount accountTwo = getAccount( toAccount);
if(accountTwo == null){
throw new IllegalArgumentException("account number not found");
}
accountOne.withdraw(amount,pin);
accountTwo.deposit(amount);
}
}