-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bank.java
95 lines (73 loc) · 2.23 KB
/
Bank.java
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
import java.util.ArrayList;
public class Bank {
private static final int DEFAULT_BALANCE = Integer.MIN_VALUE;
private String name;
private ArrayList<Client> clients;
public Bank(String name) {
this.name = name;
clients = new ArrayList<Client>();
}
public String getName() {
return name;
}
// Add a client to the list of clients
public void addClient(String cardNumber, String pin, int checkingBalance, int savingsBalance) {
Client client = new Client(cardNumber, pin, checkingBalance, savingsBalance);
clients.add(client);
}
// Check if the cardNumber exists
public boolean cardExists(String cardNumber) {
Client client = getClient(cardNumber);
if (client != null) {
return true;
}
return false;
}
// Check if the pin for a specific card is correct
public boolean pinCorrect(String pin, String cardNumber) {
Client client = getClient(cardNumber);
if (client != null && client.getPin().equals(pin)) {
return true;
}
return false;
}
// Get the client for a specific card number
private Client getClient(String cardNumber) {
for (Client client : clients) {
if (client.getCardNumber().equals(cardNumber)) {
return client;
}
}
return null;
}
// Get the balance for a checking account given a card number
public int getCheckingBalance(String cardNumber) {
Client client = getClient(cardNumber);
if (client != null) {
return client.getCheckingBalance();
}
return DEFAULT_BALANCE;
}
// Get the balance for a savings account given a card number
public int getSavingsBalance(String cardNumber) {
Client client = getClient(cardNumber);
if (client != null) {
return client.getSavingsBalance();
}
return DEFAULT_BALANCE;
}
// Update checking balance given card number
public void updateChecking(int quantity, String cardNumber) {
Client client = getClient(cardNumber);
if (client != null) {
client.updateChecking(quantity);
}
}
// Update savings balance given card number
public void updateSavings(int quantity, String cardNumber) {
Client client = getClient(cardNumber);
if (client != null) {
client.updateSavings(quantity);
}
}
}