-
Notifications
You must be signed in to change notification settings - Fork 0
/
Branch.java
68 lines (55 loc) · 1.89 KB
/
Branch.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
package com.company;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class Branch {
private static final DecimalFormat df = new DecimalFormat("0.00");
private String name;
private ArrayList<Customer> customers;
public Branch(String branchName, ArrayList<Customer> myCustomers) {
this.customers = myCustomers;
this.name = branchName;
}
public static Branch createBranch(String branchName) {
ArrayList<Customer> myCustomers = new ArrayList<>();
return new Branch(branchName, myCustomers);
}
public String getName() {
return name;
}
public ArrayList<Customer> getCustomers() {
return customers;
}
private Customer findCustomer(String customerName){
for (int i = 0; i<this.customers.size(); i++) {
Customer customer = this.customers.get(i);
if (customer.getName().equals(customerName)) {
return customer;
}
}
return null;
}
public boolean newCustomer(String customerName, double startingBalance) {
if (findCustomer(customerName)!=null){
System.out.println("Customer is already in system.");
return false;
}
else {
Customer customer = new Customer(customerName, startingBalance);
this.customers.add(customer);
System.out.println("Customer " + customerName + " added.");
return true;
}
}
public boolean addCustomerTransaction(double deposit, String name){
//overloading method in customer. This is called first, then passed
// to the customer version.
if (findCustomer(name)==null){
System.out.println("Customer name invalid.");
return false;
}
else{
findCustomer(name).addTransaction(deposit);
return true;
}
}
}