Project 2

College Information System (CIS) – Phase 2

Problem

Thanks for everyone’s hard work that help make Phase 1of CIS a success. The VP for Technology is impressed by the promises this new system entails. Before bringing it to the President’s attention, he wants us to show how the system deals with new courses that will be added to the College’s brand new Transportation (TSN) program. So he is asking you to add a module to your CIS to allow students who will be taking the Trucking course to use your system to simulate a driving class.

Requirements & Analysis

In this phase, you need to add a new Trucking course (TSN101) to the enrollment file. You also need to add a professor who qualifies for teaching this course, as well as students who want to take the course, into the two user files. Make sure that you are in that class so that you can test your new programs with your login credentials.

You need to modify the interface for the class list seen by the student, add option buttons so that a student in TSN101 can click on a button to open the simulation window.

The simulation window should include two parts: a simulation panel on top that takes up most of the space, and a control panel at the bottom that provide buttons to move the truck forward or backward, stop the truck, or edit the truck (i.e., change its color). Obviously, the truck should be displayed in the simulation panel, on top of some (colored) pavement. To impress the college executives, you may add some (colored) shapes to decorate the environment. One thing that you must add though is the traffic lights, which needs to be placed near the center of the driveway. The student needs to stop the truck before a red light! A police car will be roaring into the scene upon a violation.

The design we discussed in Lab 4 can find its application here. The Car class we’ve coded together can be extended (or rewritten if you prefer) into a PoliceCar class. I’ll leave the details to you so you can show your creativity. The only requirement on that is it should look like a police car (not like the one we’ve seen in class).

Design

To meet the requirements for pavement and traffic lights (and any other decorative shapes), you may consider to have classes that implement the Colorable interface. Especially a colorable TrafficLight class will make changing color easier. The difference here for the traffic light is only three colors are allowed, and to set the light to one of the colors will cause only the light in the specific color to show in color and the other two will be in dark gray (or a dull shade of the corresponding color).

Use the mock-up screenshot on the next page as a reference when you plan for your driving school layout. For the vehicles, the tires will always be black, but the spokes (or central area of a wheel)should be painted in the same color as the car body. Optionally, windows can be painted with white (or the background color of the simulation window).

You need to use a while loop to keep the truck moving at a constant (positive, negative, or zero) speed. The user can press the control buttons to change the speed.

The truck can be initialized with a color of your choice or with no color at all. (Except that the tires should be black.) To allow the user to change the color of the truck, the Change Color button should provide options to the user either by showing an option dialog or by popping up a dialog using the JColorChooserclass. See the code snippet for an example.

Color newColor = JColorChooser.showDialog(window,

"Please choose a color for your truck.",truck.getColor());

truck.setColor(newColor);

To detect the location of the truck, you may add two abstract methods getHeadPosition andgetRearPosition in the Vehicle class to enforce its subclasses to implement them so as to return the x coordinate at the front and back extremes of a specific vehicle object. Check in your loop to see if your truck is running crossing the red light (that is the getColor method of the TrafficLight object returns Color.RED). The truck should be stopped when that happens and a police car should run into the screen at that moment.

Coding and Commenting

As specified in Project 1.

Testing

Use the modified data files as described to test your program. Try your best to test the following cases:

-Login with a valid id for a student in the TSN101 class;

-Change color for the truck as appropriate;

-Test moving forward, backward, and stop;

-Test red light violation and show the police car rolling in.

Deliverables and Due Date

Send in code and screen shots in printed format by 10/6.