View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Fall2001 Midterm Review: Write Smalltalk Code

Link back to Fall 2001 Midterm Review

Quick and dirty, no optimization attempted... you could do it a lot better than this.

myPen := Pen new.
myString := 'CS2340'.

myPen up.
myPen goto: 50@50.
myPen north.
myPen turn: 90.
myPen down.
myPen go: 150.
myPen turn: 90.
myPen go: 100.
myPen turn: 90.
myPen go: 150.
myPen turn: 90.
myPen go: 100.

myPen up.
myPen goto: 75@75.
myPen north.
myPen turn: 90.
myPen down.
myPen go: 100.
myPen turn: 90.
myPen go: 50.
myPen turn: 90.
myPen go: 100.
myPen turn: 90.
myPen go: 50.

myString displayAt: 100@100. -Allen Tyner


myPen := Pen new.
myPen up.
myPen goto: 250@250.
myPen north.
myPen down.
4 timesRepeat: [ myPen go: 200. myPen turn: 90 ].
myPen up.
myPen goto: 275 @ 225.
myPen north.
myPen down.
4 timesRepeat: [ myPen go: 100. myPen turn: 90 ].
'CS2340' displayAt: 300 @ 200.

Mine gives more of a square look but it's handy when you're pressed for time to use a little bit less code.
Jared Parsons
Can get more rectangular with 2 timesRepeat: Mark Guzdial
a square is, by definition, a rectangle, so this code would still be acceptable, no? chris adams

myPen := Pen new.
myPen up.
myPen goto: 250@250.
myPen north.
myPen down.
2 timesRepeat: [ myPen go: 200. myPen turn: 90 myPen go: 150. myPen turn: 90].
myPen up.
myPen goto: 275 @ 225.
myPen north.
myPen down.
2 timesRepeat: [ myPen go: 100. myPen turn: 90. myPen go: 75. myPen turn: 90].
'CS2340' displayAt: 300 @ 200.
Jared Parsons

Just one tiny observation about the question, there is no north: method as is stated in the question. It's north with no parameters. Aaron Drew



Link to this Page