SDSU CS 535 Object-Oriented Programming & Design
Fall Semester, 2001
Exercise 1
    Assignment Index        
© 2001, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 04-Sep-01

Exercise 1

1. Type:

   1 + 2

in a workspace. Select the text by clicking at the beginning of the line. Run the code with “Print it” by clicking on the “Print it” icon. Select 1 + 2 again and run it with “Print it” by using the operate button on your mouse. That is click the operate button in the workspace to get a popup menu. In that menu select the “Print it” item. (The lecture notes covers which button on your mouse is the operate button.)

2. On PC or Unix there are 5 different ways to in a workspace “Do it”. What are the 5 ways?

3a. In a clear workspace type:

This is the time for all good people to come to the aid of their country

Select all the text by clicking the mouse at the beginning of the first line. Enclose the text in single quotes (‘) by pressing the ESC key and then pressing the single quote key (‘). Now type the word reverse after the last single quote. Select the entire text in the workspace and run the code with “Print it”.

3b. After doing 3a select the character s in the word “is”. Type the character x. Now press the alt key and a (alt-a) at the same time. What happened? Press alt-A (capital a). What happens? Select the character i in the word this. Delete the character. Now press alt-A. What happens?

4a. Type the following text in a workspace:

"This is a comment"
x := 3 + 2.
y := x + 1

Select the second line by clicking at the beginning of the line. Select the comment by clicking between the “ and the character T at the beginning of the line. Select the entire text by clicking at the end of the text. With the text highlighted try one at a time the “Do it”, “Print it”, “Inspect it” and “Debug it” items in the Smalltalk menu (or click on the corresponding icon). What is the result of each operation?

4b. After doing 4a click on the “Variables” tab in the workspace. You should see something like:



Click on the x. Now select the 5 and replace it with 10. Click on the right text pane with operate button and select the “Accept” item in the pop up menu. Now click on the “Page 1” tab to go back to your code. Select the last line of code (y := x + 1) and run it using “Print it”. The result should be 11. In most places in VisualWorks, when you see the value of a variable in a tool, you can change the value of that variable. This can be a useful feature in debugging.

5a. In a clean workspace type the text:

Date today

Run the code using “Print it”.

5b. Run the code Date today using “Inspect it”. When you run the code Date today a Date object is returned. “Inspect it” opens an inspector window on the date object. The window should look like:


The left pane is a list view containing self (a pseudo variable containing the object you are inspecting and the instance variables of the date object, day and year. On the right
is an edit field showing the value of the currently selected variable. Click on “day” in the left pane. What do you see in the right pane? Select the number in the right pane and change it to 10. Click with the operate button in the right pane and select the “Accept” item. Now click on “self’ in the left pane. The date displayed in the right pane will have changed.

5c. In the inspector window click on the “Methods” tab. You will get a window like:


The top left pane is list view listing categories (or groups) of methods in the Date class. When you select a category the top right list view lists the methods in that category. When you select a method, the source code for the method is displayed in the bottom text pane. Look around to see what methods are in the date class.

5d. Now click on the “Basic” tab to view the date object. Open the “Evaluation” pane by clicking on the icon



This will open a text pane on the bottom of the window. In this window type the text:

self monthName

Select this text and run it with “Print it”. (Use the operate button to get a popup menu and select the “Print it”.) What appears?

Now type in the evaluation pane the text:

self addDays: 500

Now select the text and run it with “Print it”.


Copyright ©, All rights reserved.
2000 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 04-Sep-01