CSE 341 -- Assignment 5

Due in class, Monday, March 4, 2002

Purpose: To become familiar with the Squeak programming environment; to practice writing your own Smalltalk classes; to become familiar with the Morphic framework.


  1. Experiment with the Squeak system. As usual, you don't have to hand in anything for this question.

  2. Implement a Queue class. It should understand the following messages:
    initialize 
    " initalize the instance variables "
    
    enqueue: anItem
    " add the given item to the end of the queue "
    
    dequeue
    " answer the item at the head of the queue.  error if no such item. "
    
    size
    " answer the number of elements in the queue "
    
    do: aBlock
    " evaluate aBlock with each element in the queue "
    
    Your queue should have one instance variable (items) which will hold the items in the queue. You may use any collection you find appropriate to hold the items. (HINT: check out OrderedCollection...)

  3. Implement a BankAccount class. It should understand the following messages:
    initialize: name
    " initialize the account with the given name and a zero balance "
    
    deposit: amount
    " deposit the given amount into the account "
    
    withdraw: amount
    " withdraw the given amount from the account, error if insufficient funds "
    
    balance
    " answer the account balance "
    
    owner
    " answer the account owner "
    
    Your class will probably require a couple of instance variables, for balance and account owner (a string).

  4. Modify the BouncingAtomsMorph demo. This question is purposely vague to force you to dig around the Morphic framework and learn about how the various classes work and interact. Add a new class called HungryAtomMorph that subclasses AtomMorph. It should behave just like AtomMorph, except that when it encounters other AtomMorphs, it will eat them. The more AtomMorphs it eats, the larger it becomes. Its color should also be different than other AtomMorphs.

    There are lots of ways to do this, but its probably quickest to override the initialize and bounceIn methods. You'll also need to make a few modifications to the BouncingAtomsMorph class.

    Of course, if you're keen, you can add sound effects or even other classes that have different behaviors. The more you learn about the Morphic framework, the easier time you will have completing the project!

  5. One website defines a haiku as "a contemplative poetry that valorizes nature, color, season, contrasts and surprises. Usually it has 3 lines and 17 syllabes distributed in 5, 7 and 5. It must register or indicate a moment, sensation, impression or drama of a specific fact of nature."

    In the past, we've asked new Smalltalkers to write a haiku reflecting their smalltalk experience, for instance:

    smalltalk is a brook
    become a torrent in the heavy rains
    drowning small children
    
    or
    i ride a turtle 
    into object nirvana
    self become: nil
    
    Continuing this tradition, we ask you to write your own haiku.

  6. Ask two questions about the course.


Deliverables:

We'd like you to turn in the following (hard copies only).

  1. Your 2 questions.
  2. Your haiku.
  3. Code for the BankAccount class. (fileOut/printOut the entire class)
  4. Code for the Queue class. (fileOut/printOut the entire class)
  5. Code for your HungryAtomMorph class. (ditto)
  6. Changes you made to other classes in the bouncing atoms morph. The easiest way to do this is just to printOut/fileOut the various methods that you changed. Also, give us a high-level description of what/why/where you needed to make changes. A few sentences should be sufficient.