CSE 509 -- HW #2 ================== Date Due: Monday, 21 January 2002 Goals: - Write and debug some Smalltalk code. - Gain familiarity with the Browser, Debugger and Inspector. - Gain familiarity with the actual Smalltalk class hierarchy. Note: It is okay to work together in playing with the user interface, but do not work together on writing the methods or on the class hierarchy in Part 2. The code you supply must be written by you alone. Part 1 - Smalltalk Programming: (1) Use the browser to type in the class Tree. Create a new class category, Tree-Application, and put the class there. The code for class Tree is in the class lecture notes. (2) In a workspace, practice evaluating some expressions. Build some trees and exercise all of the Tree methods. (3) Try "inspect"ing some Tree objects. Create a Tree with several sub-nodes and use the "inspect" menu command to bring up an "inspector." Walk through the tree nodes and figure out how the inspector works. (4) Artificially introduce bugs in Tree and play with the "debugger." (Try including the statement "self debug" within some method. Then, invoke the method.) (5) Write a method, called height, that returns the height of the receiver (an instance of Tree). (The height of a tree with no sub-trees is 1.) Test your method. (6) Write the remove: aString method and test it. There are some special cases that can occur when attempting to remove nodes from the Tree. Be sure your method comment tells how your method deals with these cases. (7) In an "ordered tree," all nodes are ordered by their labels. In such a tree, an in-order traversal should visit the nodes in alphabetical order. - Create a subclass of Tree called "OrderedTree." - Write an addInOrder: aString method. - Re-implement methods as necessary to make use of the fact that the tree is ordered. - In the class comment of OrderedTree, document a consistent interface such that, if a user of OrderedTree followed the prescribed protocol and only sent the messages listed in the comment, the order of the tree would never be violated. Part 2 - Smalltalk Class Hierarchy: In order to become a proficient Smalltalk programmer, you must become familiar with the existing classes and methods. Below is a list of what I feel are the most important classes and methods in the Smalltalk class hierarchy. Obviously, this is a subjective list. The goal of this exercise is to focus your attention on the most important methods and to encourage you to learn a useful subset of the class hierarchy. For each class in the list, indicate what its superclasses are. For each method, provide a short (one sentence) description of its function. If the method takes an argument, describe it. For example: Dictionary -- superclasses: Set, Collection, Object associationsDo: -- Evaluate the argument once for each key-value pair. The argument should be a block taking a single argument, which will be an Association. You may get the answers from either external documentation or by browsing Smalltalk itself. Note: some methods may be defined in a superclass of the class I listed them in. I listed the methods where they are frequently used. For example, the binary operator "," is defined in SequenceableCollection, but I rarely use it for anything other than concatenating Strings. Thus, it is included after String. Object isNil notNil = ~= == ~~ class isKindOf: error: shallowCopy deepCopy printOn: printString new (class method) Boolean not and: & or: | Collection add: addAll: do: size isEmpty with:with:with: (class method) OrderedCollection at: first last addFirst: addLast: removeFirst removeLast Set add: remove: Dictionary at: at:ifAbsent: at:put: includesKey: do: associationsDo: Association value key Array at: at:put: new: (class method) String , printOn: Character cr (class method) tab (class method) WriteStream nextPut: nextPutAll: Random Next BlockContext (Every "block" is an instance of this class.) value:value:value: whileTrue: Number < <= > >= = + - * / // \\ quo: rem: truncated rounded printString Integer to:do: What to hand in: Part 1: File out the entire category Tree-Application, including both Tree and OrderedTree classes. Then e-mail that file to harry@cs.pdx.edu with subject "OOP HW #2". Please don't submit multiple copies. Part 2: Hand-in a document. Machine formatted output is preferrable to hand-written output! Please staple everything together in the upper-left corner. Be sure your full name is on the very top page. Grading Criteria: Part 1: How "pretty" is your code? Is it well documented in complete English sentences? Is it indented logically and neatly? How clear and logical is your code? Or, does it contain unnecessary tests, unexecuted branches, etc? Is your code correct? Part 2: How understandable are your specifications? Are they short and sweet or are they imprecise, redundant, overly wordy, or just plain wrong? How much of the assignment did you complete?