-
Notifications
You must be signed in to change notification settings - Fork 1
/
Branch.java
49 lines (40 loc) · 1.25 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
package com.sayantandas;
import java.util.ArrayList;
public class Branch {
private String name;
private ArrayList<Customer>customers;
public Branch(String name) {
this.name = name;
this.customers=new ArrayList<Customer>();
}
public String getName() {
return name;
}
public ArrayList<Customer> getCustomers() {
return customers;
}
public boolean newCustomer(String customerName, double initialAmount){
if(findCustomer(customerName)==null){
this.customers.add(new Customer(customerName,initialAmount));
return true;
}
return false;
}
public boolean addCustomerTransaction(String customerName, double amount){
Customer existingCustomer = findCustomer(customerName);
if(existingCustomer != null){
existingCustomer.addTransaction(amount);
return true;
}
return false;
}
private Customer findCustomer(String customerName){
for(int i=0;i<this.customers.size();i++){
Customer checkedCustomer = this.customers.get(i);
if(checkedCustomer.getName().equals(customerName)){
return checkedCustomer;
}
}
return null;
}
}