/** * 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; } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // class TestAccount1 // @author (Irena Pevac) // @version (1) public class TestAccount1 { public static void main(String[] args) { System.out.println("BANK ACCOUNTS ACTIVITIES"+"\n"); System.out.println("Customer opens an account. "); Account1 billsAccount = new Account1("Bill Pierce", "111-11-1111"); billsAccount.report(); System.out.println("Customer deposits money"); billsAccount.deposit(3000); billsAccount.report(); System.out.println("Customer opens an account. "); Account1 tomsAccount = new Account1("Tom Jones", "312-66-1111", 300); tomsAccount.report(); System.out.print("Customer opens an account. "); Account1 suesAccount = new Account1("Sue Lee", "300-26-1144", 3000); System.out.println("Customer trys to withdraw above the balance"); suesAccount.withdraw(10000); suesAccount.report(); System.out.println("Customer withdraws money"); suesAccount.withdraw(1000); suesAccount.report(); System.out.println("Customer opens an account. "); Account1 annasAccount = new Account1("Anna Smith", "399-96-1994"); annasAccount.report(); } }