Welcome to the final homework assignment for CS1321L. This homework will pull together the Java skills you have learned this semester and apply them all to build a functioning product. You will notice that this homework is significantly longer than past assignments (which is why it is worth 100 points rather than the usual 50). For this reason, you have a full two weeks to finish it. It would be reasonable to start as early as possible. It is very important that you read through this entire project description before you implement anything.
Emergency responders such as Fire and Emergency Medical personnel need to respond to reported incidents quickly and efficiently. When an incident is reported by a call to 911, the correct number and type of units must be alerted to respond based on their proximity to the location of the incident. Because of the obvious time-sensitive nature of such emergencies, selection of these units should be automated. This is handled by a computer program called CAD Ð Computer-Aided Dispatch. Your task is to build a Simplified version of CAD, which you will call SCAD.
In order to understand how a CAD system works, we must first understand how a typical big city Fire Department dispatches its calls.
The city is divided into a grid of Box Areas, which are similar to grid squares on a map. The Fire Department has a number of stations throughout the city, each of which houses different types of Apparatus (vehicles that respond to emergencies).
If an emergency is reported at a particular address, the
dispatcher knows immediately what Box Area the address falls in, and dispatches
an Alarm to that box area. The apparatus
at the fire station in that box area (if there is one) will be the first to
respond to that alarm. If more apparatus are needed than those at that station,
then apparatus from the second closest station will be sent also. If these are
not enough, then apparatus at the third station will be sent also, and so on.
The exact number and type of apparatus for the Alarm depend on the type of
incident.
|
Engine Ð An Engine has pumps and hoses. An engine crew is responsible for getting water from a hydrant and taking hoses into a building to fight a fire. Engines can also provide first-responder care at medical emergencies. |
|
|
|
Ladder Ð A Ladder Truck has no hoses, but it does have hooks, ladders, saws, and other tools. A Ladder crewÕs job at a fire is providing access for the engine crew, ventilation, and utility control. |
|
Rescue Ð Rescue Squads carry many tools, including the ÒJaws of Life.Ó They are used to extricate people trapped in wrecked cars or other similar situations. At a fire, a Rescue crew searches a building for trapped occupants. |
|
|
|
Ambulance Ð An ambulance provides emergency medical care, including patient transport to the hospital. An ambulance will be on-hand at a fire scene to treat burn victims and the like. |
|
Battalion Chief Ð A Battalion Chief takes command of a fire or rescue scene and give assignments to other responding units. |
|
Medical Local Ð All medical emergencies fall under this category, including vehicle accidents (without entrapment). One Engine is dispatched to provide first-responder care and manpower, along with an Ambulance for transport if necessary.
Local Alarm Ð A minor fire-related incident such as a small brush fire, trash fire, dumpster fire, or vehicle fire. This type of incident warrants a single-Engine response only.
Rescue Local Ð An incident requiring Rescue services. This could be anything from a vehicle accident with entrapment to a building collapse. A considerable amount of manpower is required for this type of incident, along with command and medical services.
Box Alarm Ð All structure fires fall under this category. A box alarm requires the most manpower of any type of alarm; including many fire suppression crews, a rescue squad, command, and medical services.
Your city will be a 5x5 grid of Box Areas. Your program will read in a text file containing the assignments of apparatus to their home box areas. A Box Area is identified by a number, i.e. Box Area 1, Box Area 2, etc. The box areas on the grid are numbered sequentially left-to-right, top-to-bottom. An apparatus is identified by its type followed by a number, i.e. Engine 4, Ladder 2, Battalion Chief 1, etc.
The text file your program accepts must adhere to a specific format. Each line will initialize each successive box area in your grid. The line will contain a colon-delimited list of the box areaÕs number followed by the list of apparatus assigned there, if any. Assume that no box area will be assigned more than one apparatus of the same type. A file grid.txt is provided as an example of the format. It should create the following grid:
|
Box Area 1 |
Box Area 2 Engine 1 Ambulance 1 |
Box Area 3 Engine 2 Ladder 1 Ambulance 2 |
Box Area 4 Engine 3 Ambulance 3 |
Box Area 5 |
|
Box Area 6 Engine 4 Ambulance 4 |
Box Area 7 Engine 5 Ladder 2 Ambulance 5 |
Box Area 8 Engine 6 Rescue 1 Ambulance 6 |
Box Area 9 Engine 7 Ladder 3 Ambulance 7 |
Box Area 10 Engine 8 |
|
Box Area 11 |
Box Area 12 Engine 9 Battalion Chief 1 |
Box Area 13 Engine 10 Ladder 4 Ambulance 10 |
Box Area 14 Engine 11 Ladder 5 Ambulance 11 |
Box Area 15 Engine 12 Ambulance 12 |
|
Box Area 16 Engine 13 Ladder 6 Ambulance 13 |
Box Area 17 Engine 14 Ladder 7 Ambulance 14 |
Box Area 18 Engine 15 Rescue 2 Ambulance 15 |
Box Area 19 Engine 18 Ladder 8 Battalion Chief 2 Ambulance 16 |
Box Area 20 |
|
Box Area 21 |
Box Area 22 Engine 17 |
Box Area 23 Engine 18 Ladder 9 Ambulance 18 |
Box Area 24 Engine 19 Ladder 10 |
Box Area 25 Engine 20 Ambulance 20 |
When an alarm is dispatched to a target box area, the SCAD system builds a list of the appropriate number and type of apparatus who are closest to the target box area. Those apparatus then move to that box area and become unavailable for dispatch to other alarms until the alarm to which they have responded is cleared. When the alarm is cleared, they return to their home box areas and become available to respond to other alarms.
The two points of ambiguity here are the order in which the apparatus are added to the list, and how one determines if a particular apparatus is ÔclosestÕ to the given box area.
You should add apparatus in the order they appear in the alarm descriptions above. For instance, if you were dispatching a Box Alarm, you would first add the four closest Engines, then the two closest Ladders, then the closest Rescue, followed by closest Ambulance, and lastly, the closest Battalion Chief.
You would search for the closest apparatus using a Breadth-First-Search, or, BFS. Because this algorithm is beyond the scope of this class, we have provided its implementation for you. If you refer to the skeleton file SCADModel.java, you will notice methods to find the closest apparatus of each possible type, all of which call on the given implementation of the BFS algorithm. Keep in mind that this code will only work with the suggested design below, but feel free to modify it if you feel adventurous enough to make your own design (keep in mind that if you do, the neighboring box areas will still have to be searched in the same order that they are searched in the given code).
In a real CAD system, with many alarms being dispatched to many locations in no particular order, it is important to have a log of the order in which different events occur. Your system should have this capability as well.
When an alarm is dispatched, the following appears on the radio log:
<Alarm Type>, <List of Apparatus>, respond to Box Area <Box Area Number>
For example, if a Rescue Local was being dispatched to Box Area 17 with Engine 281, Ladder 45, Rescue 33, Ambulance 28, and Battalion Chief 4 responding, the radio log entry would be the following:
ÒRescue Local, Engine 281, Ladder 45, Rescue 33 Ambulance 28, Battalion Chief 4 respond to Box Area 17Ó
No radio log entry is required for clearing an alarm.
Given all of the above information, your systemÕs user interface should include the following components:
The user should be able to interact with the interface in the following ways:
As always, all code you submit must be properly JavadocÕd.
This system is clearly more complex than anything you have built before. For this reason, we are providing you with a suggested design below. Following this design will more than likely make this project significantly easier for you. Those who are feeling extra adventurous are free to design it however they see fit.
á Class BoxArea. This class will represent a Box Area. It will have the following members:
o An int called number, which will be the number of this box area.
o An ArrayList of Apparatus called apparatusList, which will be the list of apparatus currently in this box area, whether they are in quarters or not.
o Accessors and modifiers for the above instance variables
o A constructor that takes in a single int parameter for the number and initializes that instance variable, as well as instantiates the apparatusList
o An add method that takes in a single Apparatus and adds it to the apparatusList
o A remove method that also takes in a single Apparatus and removes that apparatus from the apparatusList. If that apparatus does not exist within the list, the method does nothing.
o A method apparatus which takes in no parameters and returns an Iterator of the apparatus within the list (keep in mind the method iterator() within ArrayList).
o A method toString which takes no parameters and returns ÒBox Area <number>.Ó If this were Box Area 7, the toString method would return ÒBox Area 7Ó
á Abstract class Apparatus. This class will represent a generic Apparatus, and include properties and actions common between all Apparatus. It will have the following members:
o A BoxArea named homeBoxArea, which will represent this apparatusÕ Home Box Area, as read in from the text file.
o A BoxArea named currentBoxArea which will represent the box area the apparatus is currently in
o An int number which will represent the ApparatusÕ number
o A boolean inQuarters which will represent whether or not the Apparatus is in quarters (necessary because an apparatus could be responding to an alarm in its home box area, and thus not be in quarters, but still be in its home box area)
o Accessors and modifiers for the above variables.
o A constructor that takes in a homeBoxArea and a number, and initializes those values. It should also set currentBoxArea to the homeBoxArea, and set inQuarters to true.
o A method moveTo that takes in a destination BoxArea. This method should remove the apparatus from quarters. If the destination is someplace other than the home box area, this method should remove the apparatus from its home box area and add it to its destination box area, then set the current box area to the destination.
o A method returnToQuarters that takes no parameters, and basically Òun-doesÓ the process done by moveTo.
á Class Engine. This class will represent an Engine, and be a subclass of Apparatus. It will be a relatively simple class, only containing the following members:
o A constructor taking in a home box area and a number. All this constructor has to do is chain to the parent classÕ constructor.
o A toString method that functions the same way as the one in BoxArea. An Engine whose number is 6 would return ÒEngine 6Ó for itÕs toString
á Classes Ladder, Rescue, Ambulance, and BattalionChief that work the same way as Engine.
o A BoxArea called box, which represents the box area to which this alarm is being dispatched.
o An ArrayList of Apparatus called apparatusList, which will contains the list of apparatus assigned to this alarm
o A constructor that takes in a single BoxArea parameter, and initializes box to this value, as well as instantiating the list
o A method add that takes in a single Apparatus parameter, which is the apparatus to add to this alarm. It should move the apparatus to the alarmÕs box area and then add it to the apparatusList
o A method apparatus which takes no parameters and behaves the same as that in BoxArea
o A method clear that takes no parameters and clears the alarm. It should cycle through all the apparatus in the alarm, return them to quarters, and remove them from the apparatusList
o A method toString that will return the entry for the radio log minus the type of alarm. For the above Rescue Local example, this toString method would return ÒEngine 281, Ladder 45, Rescue 33 Ambulance 28, Battalion Chief 4 respond to Box Area 17.Ó
á A class MedicalLocal that extends Alarm. It will follow the same design pattern as Engine by including the following members:
o A constructor that takes in a box area and chains to the constructor from the parent class
o A toString method that returns the full radio log entry as defined above.
á Classes LocalAlarm, RescueLocal, and BoxAlarm that work the same way as MedicalLocal.
á A class SCADFileReader that will read the text file to build the initial grid. It will have the following members:
o A Scanner scan that will be used to read from the file
o A constructor that takes in a String with the name of the text file and initializes the Scanner to read from that file.
o A method readGrid that takes no parameters and returns the 2-D array of BoxAreas represented by the file.
á A class SCADModel that pulls all of the above model components together. The skeleton version of this class that implements the BFS search algorithm is provided here. You will need to add the following members to the given class:
o An ArrayList of Alarms called alarms. This will hold the list of active alarms
o A constructor that takes in a String for the filename, instantiates the list of alarms, and uses the SCADFileReader class to build the grid from the filename.
o A method getBoxArea that takes in an int and returns the BoxArea from the grid with that number. You will have to calculate the position in the grid to find this box area.
o A method dispatchMedicalLocal that takes in a BoxArea. This method instantiates a MedicalLocal object with the given box area, adds the closest Engine and then the closest Ambulance, and adds the new alarm object to the alarms list.
o Methods dispatchLocalAlarm, dispatchRescueLocal, and dispatchBoxAlarm that work the same way as dispatchMedicalLocal, keeping in mind the order in which apparatus should be added
á A class SCADView that will be the View. This class should extend JFrame and lay out the GUI components based on the model. It will have the following members:
o A reference to the SCADModel called model
o A reference to the SCADController called controller
o A constructor that takes in a String for the filename of the grid. This constructor should instantiate the model using the filename, then instantiate the controller as defined below. The constructor should also build the GUI appropriately
o A method update that takes no parameters and updates the View according to the current state of the model
o A method addRadioText that takes a single String parameter and adds that line to the radio log
á A class SCADController that will receive events from the View and tell the model to perform the corresponding behaviors. This class will have the following members:
o A reference to the SCADModel called model
o A reference to the SCADView called view
o A constructor which will take in parameters for the model and the view,
o A method dispatchAlarm that will take two parameters, one for the type of alarm (we can make this a char), and one for the number of the box area to which we dispatch this alarm. This method gets the box area from the model, and uses it to dispatch the appropriate alarm. It then sends the appropriate radio log message to the view, and finally tells the view to update.
o A method clearAlarm that clears a given alarm.
o Appropriate event-handling methods (i.e. actionListener, etc) to capture the events and invoke the above methods.
Of course, you are welcome to extend the suggested design with any helper methods you feel are necessary to achieve the desired functionality.
Because this is the final homework assignment, you have available to you several options for extra credit on this assignment. Keep in mind that implementing some of these might require you to slightly modify your design. Any extra credit you do should be documented in a README.txt file, which you should include with your submission.
Because many fire departments lack the staffing necessary to man all of the necessary apparatus to provide adequate coverage to their response area, there are several ÒtricksÓ available to provide adequate fire service with inadequate staffing. One of these tricks is dependent staffing. When you implement dependent staffing, any station that has both an Engine and a Ladder will only have one crew to share between both those apparatus. So, when that stationÕs Engine is dispatched for an alarm, the Ladder will go out of service and will become unavailable to respond to alarms until the Engine returns to quarters. Likewise, if the stationÕs Ladder is dispatched, the Engine will go out of service. Your programÕs view should distinguish between a unit that is in service and a unit that is out of service. Implementing this functionality correctly will get you 15 points. Because this significantly affects the functionality of your program, you should have the ability to turn it on or off through a command-line argument. Document this in the README file.
Option 2: Quints (10 points)
|
Another way to provide adequate service with inadequate staffing is to use multi-purpose apparatus. One example of a multi-purpose apparatus would be a Quint. A Quint is a combination Engine and Ladder, and can be dispatched as either one. Incorporating Quints in your system will get you an extra 10 points. |
|
Option 3: Rescue Engines (10 points)
|
|
Another combination apparatus is a combination Engine and Rescue, known as a Rescue Engine. It is equipped to perform the functions of both apparatus. Implementing Rescue Engines will get you 10 points. |
Option 4: Fill-The-Box (15 points)
Sometimes, when an Engine arrives at a Local Alarm, the crew will find that the situation has deteriorated beyond their ability to control. This could happen when a car fire has extended to involve a building, or when a brush fire has become too large for one engine. The Engine will then advise the dispatcher to send other apparatus to ÒFill the Box,Ó turning the Local Alarm into a full Box Alarm. Implementing this functionality will get you an additional 15 points.
As always, you will be turning in this project on Webwork. You will turn in the following:
á All Java code necessary to run your program (including that which we give you, which you should be modifying anyway)
á If you do any extra credit options, include a README.txt file describing what you did
Good luck, and have fun!