In this lab, we will use Smalltalk to create some Count objects. There are one abstract class Count and several concrete classes which are IntegerCount, ASCIICount, DateCount, and SequenceCount. Most of source codes are already given. However, you will need to do some modifications.
mkdir cs2390 ) and then change directory into
the one you just created (cd cs2390). From there, execute
VisualWorks Smalltalk by typing visual &.
From the FILE menu, choose Settings and enter in the following line under
Source:
/remote/sun4m/sun4m/lib/visual/image/visual.sou
You should do this setting every time when you run VisualWorks Smalltalk in
Baird-Sun lab.
Now press the most right button, which is blue and looks like a file cabinet,
in the button row on VisualWork window to pop up a File List window. At the
top row of this window, type in *.st and return. Three files
which were just down loaded by you should appear below. Click at
UI.st to highlight it, and use the middle mouse button to select
file in. After you filled in this code, do the left two files in same
way.
To verify if those codes were filed in correctly you can open a System Browser now. The last three categories in the category list should be Model Views, Count Views, and Counts.
CountViewContainer new openOn: (IntegerCount new).
Highlight it and "do it." A small integer count will appear. You can do increment, decrement, and reset by click on those three buttons.
Then, do something to see if ASCIICount, DateCount, and SequenceCount work by yourself.
Is it possible to show all the functionalities of those four Counts in one
line? Yes, it is. First, select the Count class. You will need to
create some class methods instead of instance
methods. So click on the option button before class below.
In the protocol list, add a new protocol demos, and create the
following five methods in it:
integerCountDemo
CountViewContainer new openOn: (IntegerCount new)
aSCIICountDemo
CountViewContainer new openOn: (ASCIICount new)
dateCountDemo
CountViewContainer new openOn: (DateCount new)
sequenceCountDemo
CountViewContainer new openOn: (SequenceCount new)
demo
Count integerCountDemo.
Count dateCountDemo.
Count aSCIICountDemo.
Count sequenceCountDemo
Now, in the Workspace, type Count demo and run it to see if
all four kinds of counts are popped up.
counting protocol of
IntegerCount class, add a method reset
reset
"Reset myself ."
| inValue |
inValue := DialogView request: 'Reset to what?'.
self value: (inValue asNumber).
In this method, DialogView is a class used to input a String
via a dialog box. Then asNumber is a method of String to
convert it into a number.
Now, do Count integerCountDemo in Workspace. When you are
asked for the reset value, input an integer.
After the reset for IntegerCount works, you create a reset method for
ASCIICount by yourself. There is one hint for you: inValue first
is the first character in the inValue string.
0 for an IntegerCount and a for an ASCIICount.
and only when the reset button is pressed, the dialog box asking for reset
value will be popped up? To do this, you should have two different methods
concerning reset, one for initialization, another for the processing of
reset button pressing. Do this on IntegerCount. And if you have time left,
do it on ASCIICount too.
Go to the system Browser and select the Counts category. Choose the middle-button menu item File Out and type a file name (or default Counts.st) when prompted. Do same thing also on Count Views category. Send the file to your TA by using the relevant command
Attention: (1) mail all your codes together instead of in several times; (2) add a subject to the mail.
(1:30-3)
cat Counts.st Count_Views.st | mail -s "lab 2 - YOUR NAME" joita@cc.gatech.edu
OR (3-4:30)
cat Counts.st Count_Views.st | mail -s "lab 2 - YOUR NAME" jyan@cc.gatech.edu
OR (4:30-6)
cat Counts.st Count_Views.st | mail -s "lab 2 - YOUR NAME" smk@cc.gatech.edu
These are required for all the lab and project hand-ins in the future.
That's all for this lab. Quit from VisualWorks before you logout.