home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / cse509 / hw2.txt < prev    next >
Text File  |  2002-03-09  |  5KB  |  212 lines

  1. CSE 509  --  HW #2
  2. ==================
  3.  
  4. Date Due:  Monday, 21 January 2002
  5.  
  6. Goals:
  7.  
  8. - Write and debug some Smalltalk code.
  9. - Gain familiarity with the Browser, Debugger and Inspector.
  10. - Gain familiarity with the actual Smalltalk class hierarchy.
  11.  
  12.  
  13. Note:  
  14.  
  15. It is okay to work together in playing with the user interface, but do not
  16. work together on writing the methods or on the class hierarchy in Part 2.
  17. The code you supply must be written by you alone.
  18.  
  19.  
  20. Part 1  -  Smalltalk Programming:
  21.  
  22. (1) Use the browser to type in the class Tree.  Create a new class category,
  23. Tree-Application, and put the class there.  The code for class Tree is in the
  24. class lecture notes.
  25.  
  26. (2) In a workspace, practice evaluating some expressions.  Build some trees
  27. and exercise all of the Tree methods.
  28.  
  29. (3) Try "inspect"ing some Tree objects.  Create a Tree with several sub-nodes
  30. and use the "inspect" menu command to bring up an "inspector."  Walk through
  31. the tree nodes and figure out how the inspector works.
  32.  
  33. (4) Artificially introduce bugs in Tree and play with the "debugger."  (Try
  34. including the statement "self debug" within some method.  Then, invoke the
  35. method.)
  36.  
  37. (5) Write a method, called height, that returns the height of the receiver
  38. (an instance of Tree).  (The height of a tree with no sub-trees is 1.)  Test
  39. your method.
  40.  
  41. (6) Write the remove: aString method and test it.  There are some special
  42. cases that can occur when attempting to remove nodes from the Tree.  Be sure
  43. your method comment tells how your method deals with these cases.
  44.  
  45. (7) In an "ordered tree," all nodes are ordered by their labels.  In such a
  46. tree, an in-order traversal should visit the nodes in alphabetical order.
  47.  
  48. - Create a subclass of Tree called "OrderedTree."
  49. - Write an addInOrder: aString method.
  50. - Re-implement methods as necessary to make use of the fact that the tree is
  51.   ordered.
  52. - In the class comment of OrderedTree, document a consistent interface such
  53.   that, if a user of OrderedTree followed the prescribed protocol and only sent
  54.   the messages listed in the comment, the order of the tree would never be
  55.   violated.
  56.  
  57.  
  58.  
  59. Part 2  -  Smalltalk Class Hierarchy:
  60.  
  61. In order to become a proficient Smalltalk programmer, you must become familiar
  62. with the existing classes and methods.  Below is a list of what I feel are the
  63. most important classes and methods in the Smalltalk class hierarchy.
  64. Obviously, this is a subjective list.  The goal of this exercise is to focus
  65. your attention on the most important methods and to encourage you to learn a
  66. useful subset of the class hierarchy.
  67.  
  68. For each class in the list, indicate what its superclasses are.  For each
  69. method, provide a short (one sentence) description of its function.  If the
  70. method takes an argument, describe it.  For example:
  71.   Dictionary -- superclasses: Set, Collection, Object
  72.     associationsDo: -- Evaluate the argument once for each key-value pair.
  73.                        The argument should be a block taking a single argument,
  74.                        which will be an Association.
  75.  
  76. You may get the answers from either external documentation or by browsing
  77. Smalltalk itself.  
  78.  
  79. Note: some methods may be defined in a superclass of the class I listed them
  80. in.  I listed the methods where they are frequently used.  For example, the
  81. binary operator "," is defined in SequenceableCollection, but I rarely use it
  82. for anything other than concatenating Strings.  Thus, it is included after
  83. String.
  84.  
  85.  
  86. Object
  87.   isNil
  88.   notNil
  89.   =
  90.   ~=
  91.   ==
  92.   ~~
  93.   class
  94.   isKindOf:
  95.   error:
  96.   shallowCopy
  97.   deepCopy
  98.   printOn:
  99.   printString
  100.   new (class method)
  101.  
  102. Boolean
  103.   not
  104.   and:
  105.   &
  106.   or:
  107.   |
  108.  
  109. Collection
  110.   add:
  111.   addAll:
  112.   do:
  113.   size
  114.   isEmpty
  115.   with:with:with: (class method)
  116.  
  117. OrderedCollection
  118.   at:
  119.   first
  120.   last
  121.   addFirst:
  122.   addLast:
  123.   removeFirst
  124.   removeLast
  125.  
  126. Set
  127.   add:
  128.   remove:
  129.  
  130. Dictionary
  131.   at:
  132.   at:ifAbsent:
  133.   at:put:
  134.   includesKey:
  135.   do:
  136.   associationsDo:
  137.  
  138. Association
  139.   value
  140.   key
  141.  
  142. Array
  143.   at:
  144.   at:put:
  145.   new: (class method)
  146.  
  147. String
  148.   ,
  149.   printOn:
  150.  
  151. Character
  152.   cr (class method)
  153.   tab (class method)
  154.  
  155. WriteStream
  156.   nextPut:
  157.   nextPutAll:
  158.  
  159. Random
  160.   Next
  161.  
  162. BlockContext (Every "block" is an instance of this class.)
  163.   value:value:value:
  164.   whileTrue:
  165.  
  166.  
  167. Number
  168.   <
  169.   <=
  170.   >
  171.   >=
  172.   =
  173.   +
  174.   -
  175.   *
  176.   /
  177.   //
  178.   \\
  179.   quo:
  180.   rem:
  181.   truncated
  182.   rounded
  183.   printString
  184.  
  185. Integer
  186.   to:do:
  187.  
  188.  
  189. What to hand in:
  190.  
  191. Part 1: File out the entire category Tree-Application, including both Tree and
  192. OrderedTree classes.  Then e-mail that file to harry@cs.pdx.edu with subject
  193. "OOP HW #2".  Please don't submit multiple copies.
  194.  
  195. Part 2: Hand-in a document.  Machine formatted output is preferrable to
  196. hand-written output!  Please staple everything together in the upper-left
  197. corner.  Be sure your full name is on the very top page.
  198.  
  199.  
  200.  
  201.  
  202. Grading Criteria:
  203.  
  204. Part 1: How "pretty" is your code?  Is it well documented in complete English
  205.             sentences?  Is it indented logically and neatly?
  206.         How clear and logical is your code?  Or, does it contain unnecessary
  207.             tests, unexecuted branches, etc?
  208.         Is your code correct?
  209. Part 2: How understandable are your specifications?  Are they short and sweet
  210.             or are they imprecise, redundant, overly wordy, or just plain wrong?
  211.         How much of the assignment did you complete?
  212.