/** * 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 TestAccount2 * @author (Irena Pevac) * @version (1) */ public class TestAccount2 { public static void main(String[] args) { System.out.println("BANK ACCOUNTS ACTIVITIES"+"\n"); System.out.println("///////////////////////////////// Day#1"); Account2 billsAccount = new Account2("Bill Pierce", "111-11-1111"); billsAccount.deposit(3000); billsAccount.addInterest(0.2); billsAccount.report(); System.out.println("/////////////////////////////////// Day#2"); Account2 tomsAccount = new Account2("Tom Jones", "312-66-1111", 300); tomsAccount.addInterest(0.21); billsAccount.addInterest(0.21); billsAccount.report(); tomsAccount.report(); System.out.println("/////////////////////////////////// Day#3"); tomsAccount.addInterest(0.21); billsAccount.addInterest(0.21); billsAccount.report(); tomsAccount.report(); } }