/** * interface Account1Outline describes the basic structure of * a simlified bank account * author: Irena Pevac * date June 10 2002 */ public interface Account1Outline { /* * @param amount provides the amount of money to be deposited * @return nothing */ void deposit(double amount); /* * @param amount provides the amount of money to be withdrawn * @return nothing */ void withdraw(double amount); /* * @param none * @functionality prints report about the current state of the account * @return nothing */ void report(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.text.NumberFormat; public class Account1 implements Account1Outline { // instance variables private String name; // name of the account holder protected String ssn; // social security number protected double balance; // balance for the account protected NumberFormat fmt; //Constructor for objects of class Account1 public Account1(String name, String ssn) { this.name=name; this.ssn=ssn; balance=0; System.out.println("New account created. SSN: " + ssn + ". BALANCE: "+ balance); } // Constructor for objects of class Account1 public Account1(String name, String ssn, double initialBalance) { this.name=name; this.ssn=ssn; balance=initialBalance; System.out.println("New account created. SSN: " + ssn + ". BALANCE: "+ balance); } // method deposit adds ammount specified in the parameter list // to the current balance // @param amount is amount to be added to the account's balance // @return nothing public void deposit(double amount) { balance += amount; System.out.println("SSN: "+ ssn+" account deposits " + amount); } // method withdraw subtracts the amount specified in the parameter list // from the current balance // @param amount is amount to be withdrawn from the account's balance // @return nothing public void withdraw(double amount) { if (balance>=amount) { balance -= amount; System.out.println("SSN: "+ ssn+" account withdraws " + amount); } else System.out.println("SSN: "+ ssn +" account has insufficient funds."+ " Withdrawal denied."); } // method report prints account status // @param none // @return nothing public void report() { System.out.print("NAME: \t"+ name); System.out.print(" SSN: \t"+ ssn); System.out.println(" BALANCE: \t"+ balance+ "\n"); } // method getSSN returns ssn for this account // @param none // @return ssn public String getSSN() { return ssn; } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public class Account2 extends Account1 { // Constructor for objects of class Account2 public Account2(String aname, String assn) { super(aname, assn); } // Constructor for objects of class Account2 public Account2(String aname, String assn, int startBalance) { super(aname, assn, startBalance); } // method addInterest adds interest each day // @param rate is interest rate for that day // @return nothing public void addInterest(double rate) { balance += balance*rate/365; System.out.println("SSN "+ ssn+ " account interest "+ balance*rate/365 + " added."); } } //end class Account2 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * class Bank stores a collection of accounts from Account2 class * * @author Irena Pevac * @version June 10 2002 */ public class Bank { public final int MAXSIZE=100; private Account2[] collectionOfAccounts = new Account2[MAXSIZE]; private int numberOfAccounts = 0; // method addAccount // @param account is an account that should be added to the collection // @return nothing public void addAccount(Account2 account) { if (numberOfAccounts < MAXSIZE) { collectionOfAccounts[numberOfAccounts] = account; numberOfAccounts++; } } // method withdraw withdraws given amount from the account with a given ssn // @param ssn provides ssn for the account from which to withdraw // @param amount provides the amount to withdraw // @return nothing public void withdraw(String ssn, double amount) { for (int i=0; i