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

Sp2002 Midterm Review: Write Smalltalk Code

Back to Spring 2002 Midterm Review


Not the prettiest but it works.

(Form extent:200@200)fillWhite display.
pen _ Pen new.
pen up.
pen goto: 50@100.
pen down.
pen north.
2 timesRepeat: [pen go: 50. pen turn:90. pen go:100. pen turn: 90.].
pen up.
pen goto: 60@90.
pen down.
pen north.
2 timesRepeat: [pen go: 30. pen turn:90. pen go:80. pen turn: 90.].
'CS2340' displayAt: 80@70.

randy rockinson

This is a less perty version, but it is the easiest way to hard code the problem, I think.

f := (Form extent: 200@200).
f fillWhite.
f display.
p := Pen new.
p color: (Color black).
p up.
p goto: 25@25.
p down.
p goto: 175@25.
p goto: 175@100.
p goto: 25@100.
p goto: 25@25.
p up.
p goto: 35@35.
p down.
p goto: 150@35.
p goto: 150@90.
p goto: 35@90.
p goto: 35@35.
'CS2340' displayAt: 40@40.


A little more compact version:

myPen _ Pen new.
myPen up; goto: 100@200; down.
4 timesRepeat: [myPen go: 100; turn: 90].
myPen up; goto: 110@190; down.
4 timesRepeat: [myPen go: 80; turn: 90].
'CS2340' displayAt: 130@140.

Bill Branan
However Bill, you have just drawn two squares with the text in the middle, the image shows two rectangles. I dont know how picky they may be, but their is no reason to test the bounds on a test.
Brian Pashel

Link to this Page