Project 4
CSC 140

An Intersection Simulator

Assignment

Create a Java  Applet or Application, your choice, that creates a simulator that illustrates the passage of cars through a four way intersection controlled by a stoplight.  Your simulation must clearly illustrate the random arrival of cars in all four directions at an intersection and the changing of the lights according to the normal way a stop light works.  The cars must move in the proper direction in the simulation, and must stop when blocked by the car ahead or by a red or yellow light.  However, you do not have to spend much effort making the cars or their movement realistic.  The cars can be simple ovals or rectangles and the movement can be jerky, with instantaneous starts and stops.  Each of the intersecting roads must be at least two clearly marked lanes with cars going in both directions.  You may assume that all the cars will go straight ahead.  You do not have to program any turns at the intersection.  You also do not have to make the stoplights very realistic, as long as they clearly indicate the lights in both directions and operate in the normal manner for a coordinated, four-way set of stoplights.  Design each lane so they can hold at least 12 cars waiting at a stop light.  If more cars than that show up, you may limit the arrival of new cars until the light changes.  A simple "top down" view with "north-south" and "east-west" lanes and a single four-way set of lights in the center of the intersection would probably be the simplest to program, and would be entirely acceptable for this project.

Your simulation must also have the following user controls that operate in real time:

Adjustments across reasonably broad values for the random arrival of cars from each of the four directions.  (4 independent adjustments total).

Adjustments across reasonably broad values for independent timing delays of either green or red in each of the "north-south" and "east-west" directions (2 independent adjustments total).  The green in one direction and the red in the other direction will have to be coordinated together.  You may set yellow to be the same fixed time in all directions.

Your program must also have real time read-outs of the current values set by each of the controls.  The values of the random arrival controls should be in cars per minute, and the value of the stoplight controls should be in seconds. 

Requirements

Your simulator must be implemented using the Model-View-Controller paradigm, with most of the classes and the actual running of the simulation as part of the Model.  You are welcome to use multiple Threads, but you are not required to.  Note that if you use Threads, all four stoplights should be a single Thread to make co-ordination between them easier. 

Each class must be well designed according to good Object Oriented techniques.  Pay special attention to making your classes consistent, with proper data encapsulation.  Also your classes must interact with each other with appropriate is-a, has-a and knows-a relationships.  Data passing must be kept to a reasonable minimum, with good justifications for why it is used instead of a relationship.

To implement your intersection simulator the Model-View-Controller paradigm, your Java program must have at least the following classes:

    An overall class that contains the whole application.  This class should be relatively simple in logic and structure, but may contain the timer that runs the entire simulation.
    For the Model:
        A class that simulates either a gang of four stoplights or a pair of stoplights.
        A class that simulates a single car.
        A class that simulates a lane of traffic, containing cars in a single direction.
    For the View:
        A class, probably derived from Panel or JPanel, that displays the entire intersection and all the action.  Each object in the model should draw itself when given the appropriate Graphics g object.
    For the Controller:
        A class, also probably derived from Panel or JPanel, that contains the minimum of eight controls, and passes the adjustments to the appropriate objects in the model.

You may want to use additional classes, such as a class to encapsulate the entire Model.

Your Application may be implemented using Java 1.1 or Java 2.  It must be visually well designed and intuitive for the user. It must not throw any Null Pointer Exceptions or any other un-caught Exceptions. It must be written using good Java coding style, as discussed in class, with appropriate comments.

Grading

Project 4 is worth 20 points toward the final grade.  It will be graded according to the criteria on the Project 4 Grade Report.  You will be given a hard-copy of your Grade Report during the Interactive Grading (see Date immediately following).  You are required to keep the Grade Reports for all your projects until you have your final grade at the end of the semester, in case there is a question about the grade of any of your projects.  

Date

Your project will be interactively graded on Wednesday, May 1st.  On Monday, April 29th, each student will sign up for a specific 10 minute period for grading on the following Wednesday.  You may have your project graded before May 1st, if you like, by making arrangements with the instructor.  Note:  You will only have until the Final, Wednesday, May 8th, to upgrade your Project 4 grade.  No additional grading for this course will be done after the Final on May 8th.  The number of points you have accumulated at the end of the Final will determine your grade for the course. 

badman.jpg (2629 bytes) Office:  B132 Phone:  353-2250 sbadman@parkland.edu