-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBranches.java
69 lines (62 loc) · 1.86 KB
/
Branches.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simplebanking;
import java.util.ArrayList;
/**
*
* @author adder
*/
public class Branches {
ArrayList<Customers> customer;
private String name;
public Branches(String name){
this.name = name;
this.customer = new ArrayList<Customers>();
}
//addAdditionalTransaction
public void addAdditionalTransaction(String name, double amount){
Customers exist = findCustomer(name);
if(exist!=null){
exist.addTransactions(amount);
}
}
//find customer
public Customers findCustomer(String customerName){
for(int i=0; i<customer.size(); i++){
Customers checkedCustomer = this.customer.get(i);
if (checkedCustomer.getName().equals(customerName)) {
return checkedCustomer;
}
}
return null;
}
//get name
public String getName(){
return this.name = name;
}
//get customers
public ArrayList<Customers> getCustomers(){
return this.customer;
}
// add initial transactions amount - data validation
/**
* This method protects the data or the clients name and transactions by
* call the constructor
*
* @param c
* @param initialA
* @return
*/
public boolean addNewCustomer(String c, Double initialA) {
//Call construstor from Customer Cl
if (findCustomer(c) == null) {
this.customer.add(new Customers(c, initialA));
//System.out.println("Cusomer is already a member.");
return true;
}
return false;
}
}