M206 - TMA02 Question 4
(i) Open University dialog boxes:
- (Dialog confirm: 'Is M206 your first OU course?')
- ifTrue:[Dialog warn: 'Good Luck! 1 hope you enjoy it.'.'None']
- ifFalse:[Dialog request: 'Please type in the last course you did?'
- initialAnswer: ' T102 Living with Technology'
- onCancellDialog warn: 'You mean you have forgotten already!'.'Cannot remember`]]
(ii) Modified method for debit:
debit: anAmount
If anAmount is less than the sum of the instance variables balance and overLimit, reduce the value of the instance variable balance by anAmount. Otherwise request the user to reduce the amount or cancel the transaction. If the user insists on debiting an amount which would cause the overdraft limit to be exceeded, reduce the value of the instance variable balance as above, but also set the value of the instance variable overLimit to 0. Provide the user with a series of dialogue boxes reporting the progress of the transaction. Answer true if the debit is allowed, false otherwise."
- | expectedBalance input |
- (self balance isNil) ifTrue: [self balance: 0].
- expectedBalance := self balance - anAmount.
- (expectedBalance >= self overdraft)
- ifTrue: [self balance: expectedBalance.
- (Dialog warn:' Transaction completed.' ^true]
- ifFalse:[input: = Dialog request:'This would exceed your overdraft limit. Please enter a smaller amount.'
- initialAnswer: anAmount printString
- onCancel:[(Dialog warn: 'Transaction Cancelled'). ^false].
- expectedBalance := self balance - input asNumber. (expectedBalance >= self overdraft)
- ifTrue: [self balance: expectedBalance. (Dialog warn:'Transaction completed.').^true]
- ifFalse:[Dialog warn:'Your overdraft facility has been cancelled.' self overLimit: 0. ^ false]]