Question 2-2

Write the withdraw: method of our Account class so that the balance cannot drop below 0.

Solution

withdraw: aNumber
    balance := balance - aNumber.
    balance < 0
        ifTrue: [ balance := 0 ]

Back to Review for Quiz 2