Object subclass: #Account instanceVariableNames: 'accNum name balance nWithdrawals minBalance ' classVariableNames: '' poolDictionaries: '' category: 'DebugLab'! Account comment: 'I am a bank account. Note the following specifications for the debugging excercise: Service charges should be applied whether or not balance is negative. Service charges should not be counted as withdrawals. Withdrawals are allowed only if sufficient funds are available. Withdrawals are counted until monthly processing, then start over. Minimum balance is set to current balance at the end of the month.'! !Account methodsFor: 'accessing'! accountNumber "return account number" ^accNum! ! !Account methodsFor: 'accessing'! balance "return current balance" ^balance! ! !Account methodsFor: 'accessing'! deposit: amt "deposit amt in account" balance := balance add: amt! ! !Account methodsFor: 'accessing'! name "return account holder name" ^name! ! !Account methodsFor: 'accessing'! withdraw: amt "withdraw amt if there are sufficient funds. Track number of withdrawals" balance > 0 ifTrue:[ balance := balance - amt. nWithdrawals := nWithdrawals + 1]. balance < minBalance ifTrue:[ minBalance := balance]! ! !Account methodsFor: 'initialize-release'! initialize: num name: aName "initialize account data" name := aName. accNum := num. balance := 0. minBalance := 0. nWithdrawals := 0! ! !Account methodsFor: 'periodic'! applyMonthlyCharges "Always apply monthly charges, if applicable" minBalance < 100 ifTrue:[ self withdraw: 5]. "$5 charge for minimum balance under $100" self withdraw: (nWithdrawals * 0.10) " $0.10 charge for each withdrawal "! ! !Account methodsFor: 'periodic'! monthlyInterest: rate "Add interest for the month on minimum balance." self deposit: minBalance * rate/12! ! !Account methodsFor: 'periodic'! monthlyOperations "Add interest at 5%, then apply charges" self monthlyInterest: 0.05. self applyMonthlyCharges! ! !Account methodsFor: 'printing'! print ^ 'Account Number: ', accNum printString, ' Name: ', name printString, ' balance: $',balance printString! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Account class instanceVariableNames: ''! Object subclass: #AccountList instanceVariableNames: 'table ' classVariableNames: '' poolDictionaries: '' category: 'DebugLab'! AccountList comment: 'AccountList Comment: I create and allow access to accounts. I use a Dictionary to keep a table of account objects, using account number as the key.'! !AccountList methodsFor: 'printing'! printList "Print the account balances for each account." Transcript cr; show: 'Account Balances'. table do: [:acct | Transcript cr; show: acct print]! ! !AccountList methodsFor: 'printing'! printString ^(table collect:[ :acct | acct print]) printString! ! !AccountList methodsFor: 'accessing'! account: num "return account with account num" ^table at: num! ! !AccountList methodsFor: 'accessing'! close: aNum "close account number aNum" table remove: aNum! ! !AccountList methodsFor: 'accessing'! open: aNum name:name "open an account with account number aNum and person's name" | anAccount | anAccount := Account new initialize: aNum name: name. table at: anAccount accountNumber put: anAccount! ! !AccountList methodsFor: 'initialize-release'! initialize "create empty account table using Dictionary object. See class comment for further info" table := Dictionary new! ! !AccountList methodsFor: 'periodic'! monthEnd "Process monthly operations on each account" table do: [:eachAcct | eachAcct monthlyOperations]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! AccountList class instanceVariableNames: ''! !AccountList class methodsFor: 'examples' stamp: 'IB 1/19/98 23:37'! example1 "AccountList example1" "<-- do it to see example" "Tests the AccountList Class." |bank| bank := AccountList new initialize. bank open: 1234 name: 'A. Cust'. (bank account:1234) deposit:1000. (bank account:1234) withdraw:100. (bank account:1234) withdraw:800. bank open: 21 name: 'J. Bee'. (bank account:21) deposit:2000. (bank account:21) withdraw:1901. bank open: 34 name: 'K. Tee'. (bank account: 34) deposit: 90. bank monthEnd. bank printList. bank monthEnd. bank printList.! !