Hello Friends, I need to solve the problem below. It is an Homework application.
First, this is the provided stuff for the application and the requirments:
In this project you will develop components for a vehicular traffic network simulator using the JavaBeans component framework. The system being developed is a so called discrete-event simulator, meaning that there is a central virtual clock that controls the simulation of the system. On each tick of the simulator clock, each element of the simulation is given the opportunity to do something. The clock tick interval is meant to represent an infinitesimally short time period, so the state of the system (and each component) is assumed to change only slightly during each clock tick. The simulation components also have a graphical user interface which is refreshed after each clock tick so as to provide an animation of the simulation.
The simulation models a set of vehicles which move about a network of roads and intersections. Each type of road and intersection is implemented as a separate
Java class. The simulation framework is designed to be extensible, so that new kinds of vehicles, roads and intersections can be added in the future without having to re-implement existing classes. So, each type of intersection abstracts the knowledge associated with how vehicles should safely and legally pass through that particular type of intersection. The vehicles themselves and the roads that connect them know nothing about specific types of intersections. At any given time, each vehicle is under the control of exactly one traffic component (either some form of road or some form of intersection). Vehicles can also move from one traffic component to an adjacent traffic component.
The interaction between traffic components is abstracted by an interface called EntryPoint. In the case of a 4-way crossroad intersection, there are four separate EntryPoint interfaces that it exposes: north, east, south and west. A single lane road by comparison, has only one entry point. If vehicles can move directly from traffic component A to traffic component B, then A requires a reference to object B (of type EntryPoint) in order to communicate with it. Traffic component B doesn�t need to directly know about traffic component A, it simply receives messages from that component about vehicles wishing to enter traffic component B.
The EntryPoint interface provides an operation called isClear which is invoked to determine if it is safe and legal for a new vehicle to enter via this entry point. Method isClear returns true if and only if it is safe and legal to enter. This decision may be influenced by the direction (left, right or straight) that the vehicle wishes to turn within the new component. The isClear operation therefore takes the turn direction as a parameter.
The decision as to which way to turn must be made by the vehicle in question prior to arriving at the entry point. In order to make this decision, the vehicle needs to know what the possible set of turn directions are at the upcoming component (when approached from this entry point). The EntryPoint interface therefore provides a property called TurnDirections which returns a list of possible turn directions (left, right and/or straight). The vehicle class provides a method called selectTurnDirection which takes a list of possible turn direction and randomly chooses one of them. The turn direction currently selected by a vehicle is accessible via a public property called NextTurnDirection. If isClear returns false then the vehicle must remain at the end of the previous traffic component until isClear become true. If isClear returns true, then the Enter method may be called to transfer the vehicle to the new traffic component. The caller should at that point relinquish control of the vehicle.
Some of the classes and interfaces required to implement this system have already been developed and will be supplied.
The classes that have already been implemented are a four-way CrossRoad intersection and an abstract one Lane road with four concrete subclasses NorthLane, SouthLane, WestLane and EastLane specialized for travel in each of those directions. The EntryPoint interface and TurnDirection enumerated type have also been provided.
Your task is to complete each of the following four development exercises.
Part A � Generating Events
In this part of the project you will implement a non-visual JavaBean component called SimulationClock that will control the overall simulation. Remember that a JavaBeans component is simply a plain old Java class that happens to follow a number of naming conventions. So, start by adding a new Java class called SimulationClock inside the Traffic package (just like the existing traffic components). The SimulationClock is responsible for generating the Tick events that cause each of the other traffic components to do their thing. So, the SimulationClock class will need to have a method called fireTickEvent which when called will notify all listeners that a Tick event has occurred.
The SimulationClock will also need methods that follow the standard JavaBeans naming conventions for adding and removing listeners for simulation events. For this purpose you will need to design a new interface (called SimulationListener) that derives from java.util.EventListener. SimulationListener will need to implement a Tick method as well as another method called Reset. The Reset event is fired to instruct simulation components to reset themselves, i.e. to remove all vehicles they are currently controlling. The Tick and Reset events will need to take an event parameter of a class that derives from java.util.EventObject. Make sure you strictly follow all JavaBeans� naming and subclassing conventions for creating events, otherwise the NetBeans wizard used in the subsequent parts will not be able to automatically recognize your events.
Note: do not change the existing CrossRoad and Lane classes in any way. In particular, do not change them to implement this new interface or change the parameters of the Tick or Reset methods (we will connect the events to these methods visually in Part C without the need for them to actually implement the listener interface).
The SimulationClock should use the javax.swing.Timer class to help it periodically call its fireTickEvent method. The timer should be used to notify the SimulationClock itself, i.e. the SimulationClock will need to implement the ActionListener interface. The interval between ticks should be controlled by a property of the SimulationClock called Interval and its value should default to 1 millisecond. The timer should be started automatically as soon as the SimulationClock object is constructed.
How do I complete the above Part. I created SimulationClock with a normal interval property with Set& get methods. I added ActionListener & actionPerformed() (didn't write any thing in it. I created a method fireTickEvent() & am calling in setInterval, once the ;atest interval value is set. In SimulatorListener, I added 2 methods i.e. Tick & Reset (without body) with EventObject parameter. I am getting confused, how to proceed. I believe that in SimulationClock class, NorthLane, EaseLane, WestLane, SouthLane should be members as each extends Lane which implements Tick() & it makes all vehicles present in the lane to move ahead or take turn. But am not sure and am highly confused.
It would be good if anybody can guide me. I want to do on my own, but need some guidance. Any help is highly appreciative. Hope to get help ASAP as I need to finish this in 2 days. Please help me.
Thanks