Bank Accounts Redux

posted by: Ms. Martin 3 February 2011 No Comment

A bank offers two kinds of accounts: checking and savings.  Sound familiar?  You’ve modeled this in Scheme!

Checking accounts contain a customer’s name, current balance and a count of transactions (how many withdrawals and deposits). Savings accounts contain a customer’s name, current balance, and interest rate.

Both checking accounts and savings accounts can be treated as BankAccounts but BankAccounts can’t be instantiated.  All BankAccounts MUST define an isFDICInsured method that returns true or false.  BankAccounts know how to deposit, withdraw, transfer an amount to another account and print themselves.  Any transaction that occurs in a checking account should increase the transaction counter.

Savings accounts have an addInterest() method that calculates and deposits interest into them when called.

Checking accounts have a deductFees() method that calculates fees to apply and withdraws them from the account.  You should have two static class constants: FREE_TRANSACTIONS (3 free transactions a month) and TRANSACTION_FEE ($2 per additional transaction).

Note that when you transfer between bank accounts, you withdraw from the source account and deposit to the target account.  Those are polymorphic calls that will behave differently based on the actual account type.

Use good encapsulation.  Maintain reasonable invariants — for example, throw an exception if your balance is about to become negative.  Your client class should thoroughly test every method.

The battle is on

Go back to your Scheme implementation.  Compare and contrast.  Advantages and disadvantages to each?  Please comment!

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 2.75 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>