/** * CS139 - Programming Fundamentals * Department of Computer Science * James Madison University * @version Spring 2016 */
JMU Parking Services has contracted with the Computer Science Department to develop a parking management system for the new Mason street parking garage. They have provided the following problem specification:
When a car enters the garage the automated license plate scanner will provide the plate number, the arrival time, and indicate whether the car is compact or full-sized. After the car is scanned a large LED display should assign the car to the nearest available space. The display should notify the customer if no spaces are available.
An exit scanner will scan the license plates of departing cars. Cars should be charged $5.00 for the first 30 minutes, and $1 for each additional hour.
The system will be provided with a garage specification file containing descriptions of all parking spaces. The ordering of the spaces in the file will correspond to their proximity to the garage entrance. For example, the first three lines of the file might look like the following:
A 0,true A 1,true A 3,falseThe first comma-separated field on each line provides the label for the space, and the second field indicates whether the space is reserved for compact cars. In this example the closest space to the entrance is labeled "A 0" and it is reserved for compacts.
When a car can be assigned to a space, the appropriate label should be displayed. For example: "A 0". When a car cannot be assigned to a space, the message "NO SPACES AVAILABLE." should be displayed.
The Engineering Department will develop the hardware for the system. They are still finalizing the hardware design, but they have provided a set of hardware simulator classes that we can use for testing.
Here are the Java files provided by the Engineering department:
The following UML illustrates these classes:
Note that these diagrams only show the public members. We will treat these classes as black boxes. We don't need to worry about their implementation. Refer to the documentation comments for more details on how to use each of the public methods.
Also note that you may not need to use all public methods of these
classes. For example, the static parseScannerEvent
method is used by the PlateScanner
class during the file
loading process. You shouldn't need to call it directly.
Your final submission must include a ParkADuke
class that
conforms to the following UML diagram:
Here is an unfinished version of that class:
The constructor takes pre-instantiated hardware simulation objects along with the file name of a garage specification file specification file as described in the introduction.
You are free to add additional instance variables and private helper methods, but the public members of this class must match the UML above.
The following UML diagram represents a reasonable design for
solving this problem. You are not required to follow this
design exactly, but your solution should take an object-oriented
approach. (In other words, you will lose points on this assignment if
you try to cram all of the program logic into the run
method of the ParkADuke
class.)
The Garage
class is responsible for assigning spaces to
newly arrived cars and for storing the location of all parked cars.
(You can use the LineLoader class from
the HashMap lab to read in
the space information from the garage specification file.)
The assignSpace
method returns the label of the
assigned space, or null
if no appropriate spaces are available.
The removeCar
method returns the car associated with the
provided license plate number and removes the car from its parking space.
Each Space
object represents the state of a single
parking space in the garage. If there is currently a car parked in
that space, the car
field will store a reference to the
appropriate Car
object. If there is no car parked in
that space the car
field will contain null
.
The canPark
method will return true if the space is
currently unoccupied, and the provided car will fit. (Compact cars
can fit in any space, but full-sized cars cannot park in compact
spaces.)
Each Car
object represents a single car that has been
detected by the scanner.
The following driver is provided to help you test your finished ParkADuke class:
This is a command-line program that takes two arguments: the name of a garage specification file and the name of a file containing a sequence of scanner events.
Here are some input files along with the correct output for each.
(The format of the event files is described in the Javadocs for the
constructor of the PlateScanner
class.)
(The file data.zip contains all of these data files.)
Note that not every arrival event has a corresponding departure event. This can happen for two reasons: 1) There is no space for the arriving car, so it shouldn't be able to depart. 2) Some cars may be left in the garage when execution finishes.
Executing the test driver should look something like the following:
$ java TestDriver garage_small.txt garage_small_events_e.txt ARRIVAL SCAN: Plate: VTK 811, Time: 898 (FULL-SIZED) +----------------------------------+ |DISPLAY: A 3 | +----------------------------------+ ARRIVAL SCAN: Plate: YOG 493, Time: 4223 (COMPACT) +----------------------------------+ |DISPLAY: A 0 | +----------------------------------+ DEPARTURE SCAN: Plate: YOG 493, Time: 8106 (COMPACT) +----------------------------------------+ |GATE: Customer has been charged $6.00 | +----------------------------------------+ DEPARTURE SCAN: Plate: VTK 811, Time: 12119 (FULL-SIZED) +----------------------------------------+ |GATE: Customer has been charged $8.00 | +----------------------------------------+ ARRIVAL SCAN: Plate: XTA 320, Time: 12692 (COMPACT) +----------------------------------+ |DISPLAY: A 0 | +----------------------------------+ DEPARTURE SCAN: Plate: XTA 320, Time: 18826 (COMPACT) +----------------------------------------+ |GATE: Customer has been charged $7.00 | +----------------------------------------+
Note that your code is not responsible for printing this output directly. All of the output text is generated as a side-effect of calling the appropriate methods of the device objects.
You will probably want to test by redirecting the output to a file, then using diff or meld to compare your output to the expected output:
$ java TestDriver garage_small.txt garage_small_events_e.txt > my_small_e.txt $ meld my_small_e.txt garage_small_out_e.txt
You are not required to submit JUnit tests for this project. That said, you are strongly encouraged to test your code incrementally. You probably won't succeed on this assignment if you attempt to write all the code before doing any testing.
Before the deadline for Part A you should read this document carefully along with all of the provided code. Once you have a clear understanding of the expectations for this assignment, complete the readiness quiz in Canvas. The grading for this quiz will be all or nothing: your score on the quiz will be 0 if you miss any questions. If you do not successfully complete Part A, you cannot receive any credit for Part B.
Zip ParkADuke.java along with all of the other files used in your solution. You do not need to submit any of the engineering files files described in Section 2 above. Submit the .zip file through Web-CAT.
All of the files you submit must conform to the CS 139 Style Guide.
Your submission will be graded using the following criteria:
Points | |
---|---|
Part A Quiz | 10 |
Part B Web-CAT Correctness | 40 |
Part B Checkstyle Tests | 20 |
Style and Code Organization | 30 |
If Web-CAT deducts any points for correctness you will receive at most 50% of the points for that part.
Once again there will be a penalty for excessive submissions. The first 10 submissions for each part are free. Each submission beyond 10 will result in a .5 reduction in the final score.
This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.