CS 2390 - Lab # 2: The Count in SmallTalk

What We're Gonna Do:

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.

Step One: Setting up Environment:

It is not a good idea for you to put all your labs and projects in your home directory. So you'd better make a directory to work in for this quarter ( 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.

Step Two: Filing in Source Code:

In this lab, you will need the following classes: You can get the code for those classes by clicking on it, and then use Save As from File menu of Netscape to get copies of your own. Please make sure that those files are saved in your directory for this course.

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.

Step Three: Running The Count Classes:

In the Workspace, type in

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.

Step Four: Changing Reset Value On-Line

We can set the reset value of a Integer Count when it is required to reset. First, you need to click instance option button to add an instance method. In the 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.

Step Five: Further Exploration

Now every time when you activate an IntegerCount or ASCIICount, a reset value will be asked. How about we assign the initial reset values as before, which means 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.

Step Six: Turning in the code

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.