Create an object of the tally% class and send it some messages.
Confirm that it works like the tallies in the lab on object-oriented
programming.
Create a queue, enqueue the symbols 'foo, 'bar, and 'baz, dequeue the front element, and check the size of the queue.
Add a :print message to the queue class.
Translate our implementation of stacks (from the reading on stacks) into a DrScheme class definition.
Define a traffic-light% class that is always in one of four states,
represented by the symbols 'red, 'yellow, 'green, and
'flashing-red. A traffic light can respond to four messages:
:show, which returns the current state.:emergency!, which sets the state to 'flashing-red,
regardless of what it was before.:ok!, which takes one argument -- one of the symbols 'red, 'yellow, or 'green -- and sets the state to that
symbol.:cycle!, which has no effect if the current state is 'flashing-red, but changes a 'green state to 'yellow, a
'yellow state to 'red, and a 'red state to 'green.Give the class a initialization parameter specifying its initial state.
From the tally% class defined in the
reading, derive a clicker% class, containing objects that receive
the same messages as tally% objects, and in addition a message
called :advance!, which takes one argument, a natural number, and
increases the internal counter by the specified amount:
> (define my-clicker (make-object clicker%)) > (send my-clicker :show-contents) 0 > (send my-clicker :bump!) > (send my-clicker :bump!) > (send my-clicker :show-contents) 2 > (send my-clicker :advance! 7) > (send my-clicker :show-contents) 9 > (send my-clicker :set-contents-to-zero!) > (send my-clicker :show-contents) 0 > (send my-clicker :advance! 5) > (send my-clicker :bump!) > (send my-clicker :advance! 78) > (send my-clicker :show-contents) 84