By the end of this lab you should:
You have until before your class period on Thursday to turn in this lab. No late assignments will be accepted!
H:cs2390.
S:AppsSqueak
Squeak1.23.image
copy Squeak1.23.changes into the directory you made
above. To reduce confusion, you can rename the files
to reflect that they are your image and changes file, as
opposed to the stock 1.23 image and changes file. BE SURE TO MAKE THE IMAGE AND CHANGES FILE NAMES MATCH!. For instance,
you would make the following two copies:
S:AppsSqueakSqueak1.23.image --> H:cs2390JohnDoe.image
S:AppsSqueakSqueak1.23.changes --> H:cs2390JohnDoe.changes
C:Temp
S:AppsSqueak in NT Explorer or My Computer.
C:Temp on top of the
Squeak.exe file in S:AppsSqueak.
This should start up Squeak on your image file.
C:Temp.
If you haven't already, go ahead and start up Squeak on your personal image.
NOTE: On NT's with three buttons, the middle and right buttons are swapped!!! I don't know why.
Try it now. Left click on the background, hold the button down, select "open", and select "open transcript". An orange window labeled "Transcript" should appear. Use the left button on the borders to shrink this window down a little, and then move it to the bottom of the screen out of the way. This window is where your output will appear later on.
As a second test, left click on the background, hold the button down,
and select "save". The cursor should change for a couple of seconds
as Squeak saves a current version of your image; if you get an error
message, then you are probably using an image on a network drive, instead
of in C:Temp; exit Squeak (without saving changes), and
try the above directions again.
To create a new class you need to open a System Browser. Click the left button on the gray background area, select "open", and select "open browser". A new window should appear, which has divided into 5 subwindows ("panes"): four panes across the top and one big one at the bottom.
The leftmost pane is a list of categories. Each category contains a bunch of related classes. Create a new categary called MuppetProject by clicking the middle button in that pane, choosing "add item", and typing MuppetProject in the prompter window.
The category MuppetProject will be added to the category list, and a template for defining a new class appears. Now, create the Muppet class:
NameOfClass to Muppet
'name greeting'.
Be sure not to erase the quotes!
''. This means that there
are no class variables.
Object specificaton alone, so that
the superclass of Muppet will be Object.The result should look something like this:
Object subclass: #Muppet
instanceVariableNames: 'name greeting'
classVariableNames: ''
poolDictionaries: ''
category: 'MuppetProject'
When you think you have got it, tell Smalltalk to accept
the code: click in the text pane with the middle button
and choose accept.
Assuming you have made no syntax errors, the class should appear in the
second pane of the browser. If you have made syntax errors, correct them
and try again.
Now create the FrogMuppet and GrouchMuppet classes. What is the superclass of these classes? Do they have any instance or class variables?
Now you will define the behavior of the Muppet class, which will be inherited by the FrogMuppet and GrouchMuppet classes.
The third list in the System Browser is for protocols, which are groups of related methods. Create a protocol for the Muppet class by selecting that class, choosing "add item" by center-clicking in the protocol list, and typing in accessing at the prompt.
A method template will appear in the text pane. To add each new method, you will replace the top line with the message name, place a comment in the double quotes, and insert the text at the bottom. After editing the template for the new method, you accept it to tell Smalltalk to compile it.
Create two methods for accessing the name variable, as follows.
First, create a name method
by changing the template in the text pane to look like this:
Now, use middle-button-menu to choosename ^name
accept.
Click on name in the rightmost pane, deselecting it, so that the method template reappears. Edit the template to create a new method as follows:
name: aName name := aName.
Again, accept it. You now have two methods in the accessing
protocol, name and name:.
Create a protocol for initializing, and place the following method inside it:
initialize greeting := 'I am an abstract muppet'.
Create a protocol for greeting, and place the following method inside it:
greet Transcript cr. Transcript show: greeting; cr. Transcript show: 'I am ', name; cr.
Open a workspace to test your code in, using the "open" menu from the background menu. Type the following code into the workspace:
| muppet | muppet := Muppet new initialize. muppet name: 'Jim Henson'. muppet greet.
Select the text with the mouse, click the center button, and choose "do it". Do you get what you expect?
Frogs and Grouches differ from ordinary Muppets in their greeting. For each class create initialization protocols. Create an initialize method for both classes that changes the greeting. The FrogMuppet greeting should be 'Hi Ho', and the GrouchMuppet greeting should by 'Go Away'.
Test your muppets with the following code:
| frogMuppet grouchMuppet | frogMuppet := FrogMuppet new initialize. grouchMuppet := GrouchMuppet new initialize. frogMuppet name: 'Kermit the Frog'. grouchMuppet name: 'Oscar the Grouch'. frogMuppet greet. grouchMuppet greet.
Now, let's make the muppets interact. Write a method in the Muppet class that:
When you execute the following code:
| frogMuppet grouchMuppet | frogMuppet := FrogMuppet new initialize. grouchMuppet := GrouchMuppet new initialize. frogMuppet name: 'Kermit the Frog'. grouchMuppet name: 'Oscar the Grouch'. frogMuppet greetByName: grouchMuppet. grouchMuppet greetByName: frogMuppet.
You should see:
Hi Ho, Oscar the Grouch! I am Kermit the Frog! Go Away, Kermit the Frog! I don't care! I am Oscar the Grouch!
You should turn in a fileOut of the code you wrote.
To make the fileout, make sure the
MuppetsLab class category is selected in a System Browser,
and then choose "file out" from the middle-button menu in class-category
pane (the one on the top left).
The system will silently create a text file named MuppetsLab.st.
Copy MuppetsLab.st to your 2390 directory (on your H: drive).
Mail the file to your TA any way that is convenient. Here is one way to do so:
Run from the Start menu and type in:
telnet lennon.cc
cd ~/cs2390 (or wherever you put your code)
/usr/ucb/mail -s "TI,Lab1,My SocialSecurity Number or Student Number" cs2390@prism.gatech.edu < Muppet
sLab.st
(Replace My SocialSecurity Number or Student Number with your student number, e.g., 345544545).
News Page | CS2390 Win'98 Home Page | CS2390 CoWeb | STABLE | BOOST
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 1/13/98; 1:06:03 PM