1 package bank; 2 3 import java.util.Collection ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 7 10 public class Client { 11 protected String lastName; 12 protected String firstName; 13 protected String address; 14 protected Collection accounts; 15 protected Agency agency; 16 17 public Client() { 18 } 19 20 public Client(String lastName, 21 String firstName, 22 String address, 23 Agency agency) { 24 this.lastName = lastName; 25 this.firstName = firstName; 26 this.address = address; 27 this.agency = agency; this.accounts = new ArrayList (); 29 } 30 31 private Account getAccount(String number) { 32 Iterator it = accounts.iterator(); 33 while(it.hasNext()) { 34 Account a = (Account) it.next(); 35 if (a.number.equals(number)) { 36 return a; 37 } 38 } 39 return null; 40 } 41 42 public synchronized Account createAccount(String number) { 43 Account a = getAccount(number); 44 if (a == null) { 45 a = new Account(number, this, 0); 46 } 47 return a; 48 } 49 50 public synchronized void removeAccount(Account a) { 51 if (accounts.remove(a)) { 52 a.client = null; 53 } 54 } 55 56 public synchronized void removeAllAccounts() { 57 Iterator it = accounts.iterator(); 58 while(it.hasNext()) { 59 Account a = (Account) it.next(); 60 a.client = null; 61 } 62 accounts.clear(); 63 } 64 65 } 66 | Popular Tags |