CSG 107: Problem Set 9

Due: Wednesday, April 1, 2009 at 5:00 pm.

Purpose:

This is the first part of a two-part assignment. The goal of this first part is to help you learn to work with imperative objects and the publish/subscribe pattern, and to give you some experience with iterative refinement of a problem.

As always, you must follow the design recipe. The deliverables for the design recipe are as in the preceding problem set.

Finger Exercises:

These are based on the examples we did in class.

  1. Instead of starting with a single ball, start with a list of balls in various locations. Stop the simulation when the first one reaches the limit.
  2. Same as the previous, but stop when all balls have reached the limit.
  3. Similar to the ball-spawning example, but when each ball reaches its limit, it should spawn exactly two balls, at distinct x coordinates (so you can see them easily).
  4. Same as the previous, but stop when any ball reaches the right-hand edge of the canvas.

Required Problems:

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.

  1. Your task is to create a traffic simulation. The simulation involves cars on a street. Cars enter the street at a regular rate and proceed from the left end of the street to the right end, where they travel off the screen.

    A car is a rectangle 10 pixels high and 20 pixels long. It travels at 20 pixels per tick on the first half of the street, and 4 pixels per tick for the second half of the street.

    The street is 1000 pixels long, and the cars travel along the bottom of the canvas.

    Develop this simulation using the draw package. Run your simulation with at least 3 cars on the street at one time.

  2. Next, redo the same simulation using the idraw package.
  3. In the next iteration of the problem, there will be multiple cars on the street. Cars enter the simulation every R ticks.

    We don't want the cars to collide, so a car may not get closer than 5 pixels to the rear bumper of the car ahead of it.

    Modify your solution to the previous problem (using idraw). Observe traffic jams develop as R gets sufficiently small.


Last modified: Tue Mar 24 15:08:22 2009