29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

do:<br />

[:item |<br />

Tr<strong>an</strong>script show: item printString.<br />

Tr<strong>an</strong>script cr.]<br />

Once you have defined all the methods, you are ready to use your Org<strong>an</strong>ize r. Figure 12.7 illustrates<br />

how the Org<strong>an</strong>izer might be used. For example, I have used the Workspace to create a new Org<strong>an</strong>izer<br />

<strong><strong>an</strong>d</strong> put some entries in it. Try your Org<strong>an</strong>izer out in a similar way. Try extending it by addin g<br />

additional functionality. For example, provide a way of deleting <strong>an</strong> address or replacing it with a new<br />

one.<br />

Figure 12.7: Using the Org<strong>an</strong>izer class in a Workspace<br />

12.8 The Fin<strong>an</strong>cial M<strong>an</strong>ager project<br />

At certain points throughout the remainder of this book you will be asked to develop a small project.<br />

This project will provide the basic functionality of the Fin<strong>an</strong>cial M<strong>an</strong>ager application.<br />

The aim of the Fin<strong>an</strong>cial M<strong>an</strong>ager application is to keep a record of deposits <strong><strong>an</strong>d</strong> withdrawals from a<br />

current account. Associated with this, it should keep <strong>an</strong> up to date bal<strong>an</strong>ce, as well as allow statements<br />

to be printed.<br />

You should be able to:<br />

1. Add deposits to the account for a specified amount.<br />

2. Make payments (withdrawals) from the account for specified accounts.<br />

3. Get the current bal<strong>an</strong>ce.<br />

4. Get a statement of all payments <strong><strong>an</strong>d</strong> deposits made, in the order in which they happened. This<br />

statement should be printed to the Tr<strong>an</strong>script.<br />

To do this you sho uld use a collection class to hold the statement in conjunction with a new class<br />

subclassed off the class <strong>Object</strong>, which will hold the current bal<strong>an</strong>ce <strong><strong>an</strong>d</strong> h<strong><strong>an</strong>d</strong>le deposits <strong><strong>an</strong>d</strong><br />

withdrawals.<br />

Assuming the class you define is called Fin<strong>an</strong>cialM<strong>an</strong>ager, then you should be able to run the<br />

following <strong>Smalltalk</strong>:<br />

| aFin<strong>an</strong>cialM<strong>an</strong>ager |<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager := Fin<strong>an</strong>cialM<strong>an</strong>ager new.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager deposit: 25.00.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager withdraw: 12.00.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager deposit: 10.00.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager deposit: 5.00.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager withdraw: 8.00.<br />

Tr<strong>an</strong>script show: ‘The current bal<strong>an</strong>ce is ‘ ,<br />

Fin<strong>an</strong>cialM<strong>an</strong>ager bal<strong>an</strong>ce printString.<br />

Tr<strong>an</strong>script cr.<br />

aFin<strong>an</strong>cialM<strong>an</strong>ager statement.<br />

109

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!