S.J.S. tutorial 13: still more questions about references
SECTION(13, Tutorial 13)
m5_study(13.1)
m5_question(
m4_begin_indent
NU()m4_include(sjs-tutorials/CarTest.m4)
m4_end_indent
)
m5_question(BO(Question 13.2:) What is the purpose of the class
variable TT(serialCounter)?)
m5_question(BO(Question 13.3:) Write a method in the CLSS(Owner)
class called TT(purchase) so that:
m4_begin_indent
NU()CLSS(Car) VARI(newCar) = NEW CLSS(Car)(STRI("Mini Cooper"),NUMB(1000)); EOL
joe.purchase(newCar); EOL
m4_end_indent
NU()results in Joe's money going down by DOLLAR(1000) and Joe's car
being set to TT(newCar).)
m5_question(BO(Question 13.4:) Write a function in the CLSS(Owner)
class called TT(netWorth) so that:
m4_begin_indent
NU()SYSTEM_OUT_PRINTLN(STRI("Joe's net worth = ") + joe.netWorth()); EOL
m4_end_indent
NU()prints out Joes' money plus the value of his car, if he has a car.
You will need to use an IF TT((...)) THEN statement to test whether or
not a reference is pointing to a valid object or NULL for no object
like so:
m4_begin_indent
NU()IF (ownersCar == NULL) EOL
THEN BEGIN EOL
PD COMM(// do not access ownersCar.value as ownersCar points to no object) EOL
END EOL
ELSE BEGIN EOL
PD COMM(// do access ownersCar.value) EOL
END EOL
m4_end_indent
)
m5_question(BO(Question 13.5:) Write a method in the CLSS(Owner)
class called TT(smashCar) so that:
m4_begin_indent
NU()mary.smashCar(); EOL
m4_end_indent
NU()halves the value of Mary's car.)
m5_question(BO(Question 13.6:) Write a method in the CLSS(Owner)
class called TT(stealCarFrom) so that:
m4_begin_indent
NU()mary.stealCarFrom(joe); EOL
m4_end_indent
NU()results in Mary selling his current car (if he has one) for its
market value and Mary acquiring ownership of Joe's car. Also make Joe
relinquish ownership of his car if he has one. )
m5_question(BO(Question 13.7:) Write a function in the CLSS(Owner)
class called TT(swapMoney) so that:
m4_begin_indent
NU()CLSS(Owner).swapMoney(joe,mary); EOL
m4_end_indent
NU()swaps the money of Joe and Mary.)
m5_question(BO(Question 13.8:) Write a function in the CLSS(Owner)
class called TT(swapCars) so that:
m4_begin_indent
NU()CLSS(Owner).swapCars(joe,mary); EOL
m4_end_indent
NU()swaps the cars of Joe and Mary.)
m5_question(BO(Question 13.9:) Write a function in the CLSS(Car)
class called TT(swapSerialNumbers) so that:
m4_begin_indent
NU()CLSS(Car).swapSerialNumbers(ford,nissan); EOL
m4_end_indent
NU()swaps the serial numbers of TT(ford) and TT(nissan).)
m5_question(BO(Question 13.10:) Write a function in the CLSS(Owner)
class called TT(tradeIn) so that:
m4_begin_indent
NU()VAR CLSS(Car) VARI(joesTradeIn) = NEW CLSS(Car)(STRI("Datsun Coupe"), NUMB(3000)); EOL
joe.tradeIn(joesTradeIn); EOL
m4_end_indent
NU()results in Joe getting half the value of old car and setting his
current car to the car referenced by TT(joesTradeIn).)
m5_question(BO(Question 13.11:) Write a function in the CLSS(Owner)
class called TT(sellCarTo) so that
m4_begin_indent
NU()joe.sellCarTo(mary); EOL
m4_end_indent
NU()results in Joe's money going up by the value of his car and Mary's
money going down by the value of his car, and the ownership of Mary's
car gets transferred to Joe.)