Reading the textbook for the course, Smalltalk-80, one may discover that the authors describe Smalltalk as three major parts:
The object of this lab is to do some self-exploration of the Smalltalk
classes using various tools/methods of the Smalltalk environment.
You should learn how some code is used in Smalltalk and use those classes
for yourself. Remember, OO design stresses object reuse!
There is a tutorial on how to find information in Smalltalk at http://pbl.cc.gatech.edu/cs2390/469.html
Browse through this FAQ and do some sample of your own. For example,
after reading the FAQ you should be able to find the answers to the following
questions:
What class implements the method fork?
What methods does the Transcript have, including those found in its
superclasses?
Note: you do not need to answers these questions for the lab
After reading the FAQ, you job for the lab is as follows:
Create a CookieMonster class. Instances of CookieMonster will
use various graphical widgets found in the Smalltalk class library.
Your goal is to create the various initializing/accessing methods,
plus 3 other methods.
1) create a method called askForCookies (no arguments)
This method pops up a window with the label 'How many cookies may I
eat?'
The user must input the number of cookies. Initially a CookieMonster
will have no cookies. If the askForCookies method is called repeatedly,
then the amount inputted to the user is added to the previous amount.
You may forget about error-checking for non-numbers and problems if
the Box does not appear automatically.
To convert a string to a number, you can use the asNumber method
Example: This pop-up window is similar to the window when you
select "add new file" from the File List browser
The File List browser an instance of class FileList. You can
use this as a starting point if you wish.
2) create a method called askForPermission (no arguments)
This method pops up a selection menu with the label 'May I eat cookies?'
The user can select either yes or no. Answering this question will
change the state of the CookieMonster.
Example: an example of a selection menu is when you try to close
a Transcript or Workspace that has not been saved.
You can find what class they are by inspecting them.
Another hint: if you middle-click on a textarea and select more>>method
strings with it
you can search for anything within a method declaration, even comments
try searching for the text of one of the various selection menus such
as "Changes have not been saved."
3) create a method called eatCookies (no arguments)
If the CookieMonster has permission to eat cookies, then output a progress
bar to the screen. The progress meter will increment by 1 for every
cookie that the Cookie Monster has previously asked for. It takes
the CookieMonster half a second to eat a cookie. The CookieMonster will
eat every cookie that he has and will reset the count to zero.
If the CookieMonster does not have permission to eat cookies, output
to the Transcript 'I am not allowed to eat cookies'
Example: an example of a progress bar is when you file in code.
You can look once again at how the FileList files-in code
General Hints:
It will take some hunting to find the answers, some may take several
minutes if you are unlucky. Read the FAQ thoroughly because it will
provide you with many clues on how to find things.
Most widgets are started up by class methods, such make sure you look
at both instance and class methods.
Some classes override methods found in superclasses. Make sure
you look at a classes' superclass. Read the FAQ for easy ways to
do this.
Testing your code:
I want to execute in a Workspace:
| myCookieMonster |
myCookieMonster _ CookieMonster new initialize.
myCookieMonster askForCookies.
myCookieMonster askForPermission.
myCookieMonster eatCookies.
What I should see on the screen is:
1) a window asking for the number of cookies
then
2) a selection menu asking for permission to eat cookies (yes or no
)
then
3) depending on the previous answer output via a progress meter or
Transcript
You may assume that the statements are always called in this order, but you should still initialize any variables you may have
What to turn in:
Create a class category and create the lone class CookieMonster.
FileOut the code for the class category you created.
Once, again we will be using the online Turnin system.
In case you forgot, first go to http://triton.cc.gatech.edu/cs2390spr98
The first thing you should see is a prompt to enter your user name
and password.
For this class, your user name is your gt number (ie - gt1234a) and
your password is your SSN (ie -123456789), which you should enter without
the dashes. If you enter it correctly, you should see a new page.
Select Turnin>>Lab6
Copy and paste the FileOut code into the lower textarea labeled "Work
Content"
No documentation is necessary for the lab. (the bug has been fixed)