-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranches.java
More file actions
50 lines (39 loc) · 1.26 KB
/
Copy pathBranches.java
File metadata and controls
50 lines (39 loc) · 1.26 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
import java.util.ArrayList;
public class Branches {
private String name;
private ArrayList<Costumers> customers;
public Branches(String name) {
this.name = name;
this.customers = new ArrayList<Costumers>();
}
public String getName() {
return name;
}
public ArrayList<Costumers> getCustomers() {
return customers;
}
public boolean newCustomer(String customerName, double initialAmount) {
if(findCustomer(customerName) == null) {
this.customers.add(new Costumers(customerName, initialAmount));
return true;
}
return false;
}
public boolean addCustomerTransaction(String customerName, double amount) {
Costumers existingCustomer = findCustomer(customerName);
if(existingCustomer != null) {
existingCustomer.addTransaction(amount);
return true;
}
return false;
}
private Costumers findCustomer(String customerName) {
for(int i=0; i<this.customers.size(); i++) {
Costumers checkedCustomer = this.customers.get(i);
if(checkedCustomer.getName().equals(customerName)) {
return checkedCustomer;
}
}
return null;
}
}