CSG 107: Problem Set 10
Due: Wednesday, April 8, 2009 at 5:00 pm.
This is the second part of a two-part assignment. The goal of this
second part is to give you some experience with iterative refinement
of a problem, and further experience with patterns of sharing and
collaboration. The finger exercises give you some experience with
These are based on the examples we did in class.
Write a visitor interface for lists of integers, and write
visitors for the following operations:
- sum of the elements of the list
- length of the list
- product of the elements of the list. If any element of the
list is 0, don't multiplying the other elements.
- A list in which each element is doubled. Can this visitor use
the same interface as the others?
Note: You must use DrScheme's ProfessorJ Intermediate Student
Language. As usual, you must turn in separate files and separate
class diagrams for each problem. Use your solution to the last
question on the homework as the basis for your development.
- Add to your simulation from Homework 9 some trucks. Trucks are
just like cars, except that they are 20 pixels high and 60 pixels
long. Otherwise they behave just like cars. Arrange things so that
every 5th cycle (ie every 5R ticks), a truck enters the simulation
instead of a car. Both cars and trucks should travel at a constant
20 pixels per tick (unlike last week).
- Add to your simulation from Homework 9 some traffic lights. A
traffic light is represented as a rectangle, 30 pixels high and 20
pixels wide. It should hang with its lower edge 50 pixels above the
A traffic light is either red or green. It is red for half of
its cycle time, and green for the other half. The cycle times of
different traffic lights may be different.
Hang 3 traffic lights over your simulation. The first traffic
light should be 200 pixels from the start, with a cycle time of
20 ticks. The second light should be 500 pixels from the start,
with a cycle time of 30 ticks. The third light should be 700
pixels from the start, with a cycle time of 25 ticks. All the
lights start green.
For this question, the cars ignore the traffic lights.
- Now change your simulation so that the cars and trucks obey the
traffic lights: if a car would enter the intersection (that is, the
20-pixel wide portion of the street that is directly below the
traffic light) when the light is red, it stops at the light. If the
car or truck is already in the intersection when the light turns
red, it keeps going.
Adjust the timing of the traffic lights and watch how the
traffic flow changes.
Last modified: Fri Mar 27 17:06:14 2009