home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-24 | 3.3 KB | 128 lines |
- package COM.odi.demo.threads;
-
- /**
- * <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
- * Institution Object represents a Bank containing many accounts stored in
- * a vector.
- */
-
- import COM.odi.*;
- import java.util.Enumeration;
- import COM.odi.util.OSVector;
-
- public class Institution {
-
- /* Banks name */
-
- private String name;
-
- /* Vector of Account holders */
-
- private OSVector accountVector;
-
- /* since we dont want this to be stored in hash table we overload
- * hashCode and call super.hashCode()
- */
-
- public int hashCode() {
- return super.hashCode();
- }
-
- /**
- * Initialize name of the bank And initialize vector.
- * @name name of the bank.
- */
- public Institution(String name) {
- this.name = name;
- accountVector = new OSVector(50, 10);
- }
-
- /**
- * Get Account Object for given ssn.
- * @ssn Social Security number of required Account.
- * @return Account object for Account holder.
- */
- public Account getAccount(String ssn) {
- /* get enumeration of accountVector to browse for all Accounts */
-
- Enumeration e = accountVector.elements();
-
- while (e.hasMoreElements()) {
- Account act = (Account)e.nextElement();
- if (act.isSSN(ssn))
- return act; /* if account object is found then return it */
- }
- return null;
- }
-
- /**
- * Get Enumeration of All accounts to browse.
- */
- public Enumeration getAccountEnum() {
- /* get enumeration of accountVector to browse for all Accounts */
-
- Enumeration e = accountVector.elements();
- return e;
- }
-
- /**
- * Add new Account.
- * @thrdName is name of thread to display name with other information.
- * @name Account holders name.
- * @age Account holders age.
- * @ssn Account holders Social Security number.
- * @actType type of Account.
- * @amt initial amount.
- */
-
- public void addAccount(String thrdName, String name, int age, String ssn , String actType, float amt) {
- Account ac = new Account(name, age, ssn, actType, amt);
- accountVector.addElement(ac);
- System.out.println(thrdName+ " Account with ssn :" + ssn + " Added.");
- }
-
- /**
- * Remove Account form the vector/dtabase.
- * @threadName name of the thread.
- * @ssn Social security number of account to be removed.
- */
-
- public void removeAccount(String threadName, String ssn) {
- /* get the Account Object */
-
- Account act = getAccount(ssn);
- if (act == null)
- System.out.println(threadName + " Account with ssn :" + ssn + " does not exist.");
-
- /* Remove the Account Object from the vector */
-
- accountVector.removeElement(act);
- System.out.println(threadName + " Account with ssn :" + ssn + " Removed.");
- }
-
- /**
- * update the Account for given ssn.
- * @ssn social security number of Account to be updated.
- * @type type of updation DEPOSIT or WITHDRAW.
- * @amount amount to update
- */
- public void updateAccount(String threadName, String ssn, String type, int amount) {
-
- Account act = getAccount(ssn); /* get the Account Object */
- if (act == null) {
- System.out.println(threadName + " Account with ssn :" + ssn + " does not exist.");
- return;
- }
-
- /* update the Account */
-
- int index = accountVector.indexOf(act);
- if (name.compareTo("DEPOSIT") == 0)
- act.deposit((float)amount);
- else
- act.withDraw((float)amount);
- System.out.println(threadName + " Account with ssn :" + ssn + " updated.");
- }
-
- };
-