CS 683 Emerging Technologies: Embracing Change Spring Semester, 2001 Assignment 1 Solution Part A |
||
---|---|---|
© 2001, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 23-Feb-01 |
String>>isPalindrome ^self sameAs: self reversed
String>>isPalindrome ^self = self reversed
String>>isPalindrome self = self reversed ifTrue: [^true] ifFalse: [^false]
String>>isPalindrome | reversed result | reversed := self reversed. result := self = reversed. ^ result
Object subclass: #BankAccount instanceVariableNames: 'name balance history ' classVariableNames: '' poolDictionaries: '' category: 'Whitney-Examples'
name: aString ^self name: aString balance: 0
name: aString balance: aPositiveNumber ^self new setName: aString balance: aPositiveNumber
setName: aString balance: aPositiveNumber name := aString. balance := aPositiveNumber. history := OrderedCollection new.
balance ^balance
deposit: aPositiveNumber self adjustBalanceBy: aPositiveNumber
do: aBlock history do: aBlock
name ^name
withdrawl: aPositiveNumber self adjustBalanceBy: aPositiveNumber negated
adjustBalanceBy: aNumber balance := balance + aNumber. history add: aNumber
currentBalance "BankAccount currentBalance" Transcript show: 'Your current balance is: '; show: balance; cr. ^balance
setbalance "Set the initial balance of the account to zero" balance:=0. Transcript show: 'initial balance='. Transcript show: balance.Bad Coupling with Transcript