Student Originated Software 1997-1998
Fall Quarter

A Software Engineering Course at
The Evergreen State College

Smalltalk Code Examples - Spending

Smalltalk Code Examples - Spending






Object subclass: #SpendingHistory
	instanceVariableNames: 'cashOnHand expenditures '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Spending'
SpendingHistory methodsFor: 'transactions'
spend:anAmount on:reason
	expenditures
	   at: reason
	   put: (self totalSpentOn: reason) + anAmount.	cashOnHand := cashOnHand - anAmount.! !
SpendingHistory methodsFor: 'printing'
printOn:aStream
	super printOn:aStream.
	aStream space.
	aStream nextPutAll: 'balance:'.
	cashOnHand printOn: aStream.
	expenditures keysAndValuesDo: [:reason :amount |
	   aStream cr.	
 	   reason printOn: aStream.
	   aStream tab.
	  amount printOn: aStream]
SpendingHistory methodsFor: 'inquiries'
totalSpentOn: reason
	(expenditures includesKey: reason)
	   ifTrue:[^expenditures at:reason]
	   ifFalse:[^0]
SpendingHistory methodsFor: 'private'
setInitialBalance: anAmount
	cashOnHand := anAmount.
	expenditures := Dictionary new.
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"
SpendingHistory class
	instanceVariableNames: ''
!SpendingHistory class methodsFor: 'instance creation'
initialBalance:anAmount
	^self new setInitialBalance:anAmount
	
	

Posted Nov 3, 1997
Pavan Auman

[ SOS Home Page | Case Study | Year Long Projects | OOP ]


For more information contact
[ Evergreen Home Page | Academic Programs ]


Created by: SoSwEbGrOuP
E-mail: ringert@evergreen.edu