/* * Bank.java * * Created on October 13, 2004, 2:46 PM */ /** * * @author levenick */ import java.util.*; import java.awt.*; public class Bank { private Vector accountList; private Account currentAccount; /** Creates a new instance of Bank */ public Bank(Choice theChoice) { accountList = new Vector(); inputAccounts(theChoice); currentAccount = (Account) accountList.elementAt(0); } public int getBalance() { return currentAccount.getBalance(); } public void withdraw(int amtToWithdraw) { currentAccount.withdraw(amtToWithdraw); } public void edit(){ EditFrame theEditFrame = new EditFrame(currentAccount); } public void setCurrentAccount(String name) { for (Iterator it=accountList.iterator(); it.hasNext(); ) { Account nextAccount = (Account) it.next(); if (nextAccount.getName().equals(name)) currentAccount = nextAccount; } } private void inputAccounts(Choice theChoice) { MyReader mr = new MyReader(); while (mr.hasMoreData()) { Account newAccount = new Account(mr); accountList.add(newAccount); theChoice.addItem(newAccount.getName()); } mr.close(); display(); } private void display() { for (Iterator it=accountList.iterator(); it.hasNext(); ) System.out.println(it.next()); } public void save() { MyWriter mw = new MyWriter(); for (Iterator it=accountList.iterator(); it.hasNext(); ) { Account nextAccount = (Account) it.next(); nextAccount.save(mw); } mw.close(); } }