www.delorie.com/gnu/docs/smalltalk/gst_64.html   search  
 
Buy GNU books!


GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4.6 Moving money around

We can now create accounts, and look at them. As it stands, though, our balance will always be 0--what a tragedy! Our final methods will let us deposit and spend money. They're very simple:

 
   !Account methodsFor: 'moving money'!
   spend: amount
       balance := balance - amount
   !
   deposit: amount
       balance := balance + amount
   ! !

With these methods you can now deposit and spend amounts of money. Try these operations:
 
   a deposit: 125!
   a deposit: 20!
   a printNl!
   a spend: 10!
   a printNl!


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003