Overview

This lab will give you a taste of what it is like to work on a larger project involving other people. You will use a couple of UML diagrams and other documentation to guide implementing two classes.

Resources

Accept your instructor's invitation to the assignment in GitHub Classroom and then create a new project from version control. Your project should have the following files:

Assignment

You have been hired to implement an API for a number of parking lots in a district. Someone else is developing hardware to detect when vehicles enter or leave each lot, and you are writing classes that will be used by the hardware to measure lot usage. In particular, you are writing two classes: ParkingLot to track the number of vehicles in an individual lot, and District to track the lots in the parking district.

A design team has specified the API. This API is partially documented in the following class diagram. You will implement a class ParkingLot consistent with this diagram. You can add attributes and private methods, but you must implement the methods (with the specified parameters) as shown. The key operations are markVehicleEntry and markVehicleExit which are called when vehicles enter or exit a lot. These take a timestamp parameter which is the number of minutes since the lot opened. The design team has also written part of District.java with stubs for the portions that you need to write. Again, you may add private attributes and methods as required, but you must stay consistent with the diagram.

ParkingLot
+CLOSED_THRESHOLD: double {readOnly} = 80.0
-name: String {readOnly}
+ParkingLot(capacity: int)
+ParkingLot(name: String, capacity: int)
+displayStatus(): void
+getMinutesClosed(): int
+getName(): String
+getNumberOfSpotsRemaining(): int
+getPercentFull(): double
+isClosed(): boolean
+markVehicleEntry(timestamp: int): void
+markVehicleExit(timestamp: int): void
CLOSED_THRESHOLD determines when the lot is closed. The UML notation {readOnly} means that it is a final value and the underlining indicates it is static.
District
-lot1: ParkingLot
-lot2: ParkingLot
-lot3: ParkingLot
+District(name1: String, capacity1: int, name2: String, capacity2: int, name3: String, capacity3: int)
+displayStatus(): void
+getMinutesClosed(): int
+getNumberOfSpotsRemaining(): int
+isClosed(): boolean
+markVehicleEntry(lotNumber: int, timestamp: int): void
+markVehicleExit(lotNumber: int, timestamp: int): void
The district tracks data for all three parking lots. See the javadoc comments in District.java for notes on the parameters and implementations. The ParkingDriver class below contains tests that you can use to verify your implementation of the ParkingLot and District classes. You do not need to modify the ParkingDriver class.
ParkingDriver
+main(args: String[]): void
-testSmallLot(): void
-testTinyDistrict(): void
-testParkingLot(): void
-testFillingLot(): void
-testRefillingLot(lot: ParkingLot): void
-testEmptyingLot(lot: ParkingLot): void
-test0TimeEntryExit(): void
-testFillingTo80Percent(): void
...

Additional Notes on ParkingLot

The ParkingLot class is designed to manage the number of vehicles that can park in the lot. A vehicle enters a parking lot at a specified timestamp by calling the markVehicleEntry method and passing in the specified timestamp. Similarly, vehicles exit the lot with a call to markVehicleExit It is expected that timestamp never goes backwards. If markVehicleEntry or markVehicleExit is called with a timestamp that is before some other call, assume the sensor glitched and ignore the event.

Additional Notes on District

You should start with the initial version of the District.java file. At a minimum, you will need to write code at all of the locations marked by "TODO:".

Testing

Following best practices, another software developer has written a ParkingDriver class to test your code. One of the tests has been documented by a sequence diagram below. Note the general pattern: a message is sent to ourTown, and this generates messages to one or all of the parking lots.

The figure below corresponds to the test method testComingAndGoing in the ParkingDriver class.

It is recommended that you edit ParkingDriver.main() and comment out everything but the call to testSmallLot(). You only need to have your ParkingLot implementation complete to pass these tests. You can then continue to add back in the calls to the other tests methods ensuring that all tests pass before proceeding.

Sample Output

The output from running the final version will be as follows. Note that obtaining this output does not automatically mean your solution is working - you need to satisfy all requirements above - but it certainly is a great step in the right direction. Also note that having small differences in the results for the "heavier usage" test may also be acceptable; there can be slight differences in computations that can give you different final numbers. In the end, whether or not your solution is correct is something you must decide for yourself; tests alone cannot tell you when you are done.

Testing Small Lot...
Blacktop parking lot status: CLOSED
Finished Testing Small Lot

Testing Overfilling a Lot...
Finished Testing Overfilling a Lot

More Complete Test of Parking Lot...
Testing ParkingLot
test parking lot status: 75.0%
test parking lot status: CLOSED
test parking lot status: 50.0%
test parking lot status: 0.0%
Finished More Complete Test of Parking Lot

Testing Coming and Going...
Finished Testing Coming and Going

Testing Tiny District...
District status:
  Red parking lot status: CLOSED
  Green parking lot status: 0.0%
  Blue parking lot status: CLOSED

Lots were closed for 3 min. in tiny district.
Finished Testing Tiny District

Finished Testing Normal District...
Airport at timestamp 7:
District status:
  Brown parking lot status: 70.0%
  Green parking lot status: CLOSED
  Black parking lot status: 58.3%

Airport at timestamp 8:
District status:
  Brown parking lot status: CLOSED
  Green parking lot status: CLOSED
  Black parking lot status: 58.3%

Airport at timestamp 10:
District status:
  Brown parking lot status: CLOSED
  Green parking lot status: CLOSED
  Black parking lot status: CLOSED

Finished Testing Normal District

Finished Testing Heavily Used District...
At end of day, all lots closed 42 min.
District status:
  Pink parking lot status: 68.0%
  Blue parking lot status: CLOSED
  Gray parking lot status: 20.0%

Finished Testing Heavily Used District

All tests finished.

Acknowledgement

This laboratory assignment was developed by Dr. Rob Hasker and the CS1011 faculty.

See your professor's instructions for details on submission guidelines and due dates.