






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007
Sp2002 Midterm Review: Simulate a Motorcycle
Back to Spring 2002 Midterm Review
Comments/questions/answers?
1.
Key needs an instance of Engine, so that it can tell that engine to start. Engine needs an instance (or possibly many instances) of wheel, so that it can that/those wheel(s) to turn. Engine also needs a Process so that the engine can run in the background. Wheels need no attributes.
2.
!Key
insert
engine start.! !
Engine
start
self run.! !
Engine
run
process :=[[true]
whileTrue:
[(Delay forSeconds: 1) wait.
Transcript show: 'Putt!'
wheel turn.]]
newProcess
process priority: (Processor userBackgroundPriority)
process resume.! !
Wheel
turn
Transcript show: 'Turn!'.! !
3.
Key class methods
new
^super new initialize.! !
Key
initialize
engine := Engine new.! !
Key
remove
engine stop.! !
Engine class methods
new
^super new initialize.
Engine
initialize
wheel := Wheel new.! !
Engine
stop
process terminate.! !
4.
key := Key new.
key insert.
"Some time later"
key remove.
Michael L. Mitchell
PS Haven't tested this yet...
1. Engine needs a 'started' variable
2.
insert
Engine new start.
start
started := true.
self run.
run
[started]whileTrue:[ (Delay forSeconds: 1) wait.
Transcript show: 'Putt'.
Wheel new turn. ]
turn
Transcript show: 'Turn!'.
3. No accessor methods needed
4. Key new insert.
I tried this, it works. You can't stop it, but that's not part of the assignment.
Bill Branan
Link to this Page