home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / ODesign / SetupPSE.exe / data.z / Institution.java < prev    next >
Encoding:
Java Source  |  1997-01-24  |  3.3 KB  |  128 lines

  1. package COM.odi.demo.threads;
  2.  
  3. /**
  4.  *      <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
  5.  * Institution Object represents a Bank containing many accounts stored in
  6.  * a vector.
  7.  */
  8.  
  9. import COM.odi.*;
  10. import java.util.Enumeration;
  11. import COM.odi.util.OSVector;
  12.  
  13. public class Institution {
  14.  
  15.   /* Banks name */
  16.  
  17.   private String name;
  18.  
  19.   /* Vector of Account holders */
  20.  
  21.   private OSVector accountVector;
  22.  
  23.   /* since we dont want this to be stored in hash table we overload
  24.    * hashCode and call super.hashCode() 
  25.    */
  26.  
  27.   public int hashCode() {
  28.     return super.hashCode();
  29.   }
  30.  
  31.   /**
  32.    * Initialize name of the bank And initialize vector.
  33.    * @name name of the bank.
  34.    */
  35.   public Institution(String name) {
  36.     this.name = name;
  37.     accountVector = new OSVector(50, 10);
  38.   }
  39.  
  40.   /**
  41.    * Get Account Object for given ssn.
  42.    * @ssn Social Security number of required Account.
  43.    * @return Account object for Account holder.
  44.    */
  45.   public Account getAccount(String ssn) {
  46.     /* get enumeration of accountVector to browse for all Accounts */ 
  47.  
  48.     Enumeration e = accountVector.elements();
  49.  
  50.     while (e.hasMoreElements()) {
  51.       Account act = (Account)e.nextElement();
  52.       if (act.isSSN(ssn))
  53.      return act; /* if account object is found then return it */
  54.      }
  55.      return null;
  56.   }
  57.  
  58.   /**
  59.    * Get Enumeration of All accounts to browse.
  60.    */
  61.   public Enumeration getAccountEnum() {
  62.     /* get enumeration of accountVector to browse for all Accounts */ 
  63.  
  64.     Enumeration e = accountVector.elements();
  65.     return e;
  66.   }
  67.  
  68.   /**
  69.    * Add new Account.
  70.    * @thrdName is name of thread to display name with other information.
  71.    * @name Account holders name.
  72.    * @age Account holders age.
  73.    * @ssn Account holders Social Security number.
  74.    * @actType type of Account.
  75.    * @amt initial amount.
  76.    */
  77.  
  78.   public void addAccount(String thrdName, String name, int age, String ssn , String actType, float amt) {
  79.     Account ac = new Account(name, age, ssn, actType, amt);
  80.     accountVector.addElement(ac);
  81.     System.out.println(thrdName+ " Account with ssn :" + ssn + " Added.");
  82.   }
  83.  
  84.   /**
  85.    * Remove Account form the vector/dtabase.
  86.    * @threadName name of the thread.
  87.    * @ssn Social security number of account to be removed.
  88.    */
  89.  
  90.   public void removeAccount(String threadName, String ssn) {
  91.     /* get the Account Object */
  92.  
  93.     Account act = getAccount(ssn);
  94.     if (act == null)
  95.        System.out.println(threadName + " Account with ssn :" + ssn + " does not exist.");
  96.  
  97.     /* Remove the Account Object from the vector */
  98.  
  99.     accountVector.removeElement(act);
  100.     System.out.println(threadName + " Account with ssn :" + ssn + " Removed.");
  101.   }
  102.  
  103.   /**
  104.    * update the Account for given ssn.
  105.    * @ssn social security number of Account to be updated.
  106.    * @type type of updation DEPOSIT or WITHDRAW.
  107.    * @amount amount to update
  108.    */
  109.   public void updateAccount(String threadName, String ssn, String type, int amount) {
  110.  
  111.     Account act = getAccount(ssn); /* get the Account Object */
  112.     if (act == null) {
  113.       System.out.println(threadName + " Account with ssn :" + ssn + " does not exist.");
  114.       return;
  115.     }
  116.  
  117.     /* update the Account */
  118.  
  119.     int index = accountVector.indexOf(act);
  120.     if (name.compareTo("DEPOSIT") == 0)
  121.       act.deposit((float)amount);
  122.     else
  123.       act.withDraw((float)amount);
  124.     System.out.println(threadName + " Account with ssn :" + ssn + " updated.");
  125.   }
  126.  
  127. };
  128.