Lab 8
Start Now
## 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 * The [District.java](District.java) file contains a starting point for your `District` class. * The [ParkingDriver.java](ParkingDriver.java) file contains a program to test your implementation. ## 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 `time` 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. <table style="border: 2px solid black; font-family: menlo, monaco, consolas, monospace"> <tr> <td style="text-align: center">ParkingLot</td> </tr> <tr> <td> +<u>CLOSED_THRESHOLD: double {readOnly} = 80.0</u><br /> -name: String {readOnly} </td> </tr> <tr> <td> +ParkingLot(capacity: int)<br /> +ParkingLot(name: String, capacity: int)<br /> +displayStatus(): void<br /> +getMinutesClosed(): int<br /> +getName(): String<br /> +getNumberOfSpotsRemaining(): int<br /> +getPercentFull(): double<br /> +isClosed(): boolean<br /> +markVehicleEntry(time: int): void<br /> +markVehicleExit(time: int): void </td> </tr> </table> <div class="notetip"> `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`. </div> <table style="border: 2px solid black; font-family: menlo, monaco, consolas, monospace"> <tr> <td style="text-align: center">District</td> </tr> <tr> <td> -lot1: ParkingLot<br /> -lot2: ParkingLot<br /> -lot3: ParkingLot </td> </tr> <tr> <td> +District(name1: String, capacity1: int, name2: String, capacity2: int, name3: String, capacity3: int)<br /> +displayStatus(): void<br /> +getMinutesClosed(): int<br /> +getNumberOfSpotsRemaining(): int<br /> +isClosed(): boolean<br /> +markVehicleEntry(lotNumber: int, time: int): void<br /> +markVehicleExit(lotNumber: int, time: int): void </td> </tr> </table> <div class="notetip"> 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. </div> <table style="border: 2px solid black; font-family: menlo, monaco, consolas, monospace"> <tr> <td style="text-align: center">ParkingDriver</td> </tr> <tr> <td> +<u>main(args: String[]): void</u><br /> -<u>testSmallLot(): void</u><br /> -<u>testTinyDistrict(): void</u><br /> -<u>testParkingLot(): void</u><br /> -<u>testFillingLot(): void</u><br /> -<u>testRefillingLot(lot: ParkingLot): void</u><br /> -<u>testEmptyingLot(lot: ParkingLot): void</u><br /> -<u>test0TimeEntryExit(): void</u><br /> -<u>testFillingTo80Percent(): void</u><br /> ... </td> </tr> </table> ### 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 time by calling the `markVehicleEntry` method and passing in the specified time. Similarly, vehicles exit the lot with a call to `markVehicleExit` It is expected that time never goes backwards. If `markVehicleEntry` or `markVehicleExit` is called with a time that is before some other call, assume the sensor glitched and ignore the event. * Each parking lot has a name. To simplify testing, `ParkingLot` defaults the name to "`test`" when no name is specified. * The method `getPercentageFull` returns how full the parking lot is as a percentage. * The class constant `CLOSED_THRESHOLD` is set to 80, indicating that the lots will be closed when they are 80% full. * The method `isClosed` returns true when the lot is at least `CLOSED_THRESHOLD` percent full. When it reaches this point, an electronic sign goes on saying the lot is closed so drivers do not waste fuel circling the lot to find one of the few remaining spaces. Drivers can ignore this sign and continue to enter. You do not need to handle the case where the number of vehicles is greater than the lot capacity. * The method `getMinutesClosed` returns the number of minutes during which the lot has been closed (as defined above). You can assume this method will never be called while the lot is closed; that is, enough vehicles will have exited that the closed sign has turned off, reopening the lot to new drivers. * The method `getNumberOfSpotsRemaining` returns the number of parking spots remaining in the lot at any one time. * The method `displayStatus` prints the name of the lot and the percentage of the lot that is occupied. If the percentage is at or above the threshold, it prints "CLOSED" in place of the percentage full. When displaying a number, display just one digit after the decimal place, rounding appropriately. See the sample output below for details. ### Additional Notes on `District` You should start with the initial version of the [`District.java`](District.java) file. At a minimum, you will need to write code at all of the locations marked by "TODO:". * The method `displayStatus` has been written for you to call `displayStatus` on each parking lot. * The methods `markVehicleEntry` and `markVehicleExit` take an additional parameter in `District`, the parking lot which the vehicle is entering or exiting. * The method `isClosed` for `District` returns true if and only if all of the parking lots are closed at that time. * The method `closedMinutes` returns the number of minutes that all of the parking lots are closed at the same time. This information would be used to determine if more parking lots are needed. ### Testing Following best practices, another software developer has written a [`ParkingDriver`](ParkingDriver.java) 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. <figure>[<img src="parkingUMLtinyseq.png" />](parkingUMLtinyseq.png)</figure> The figure below corresponds to the test method `testComingAndGoing` in the `ParkingDriver` class. <figure>[<img src="lab8time.png" />](lab8time.svg)</figure> 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. <pre> 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 time 7: District status: Brown parking lot status: 70.0% Green parking lot status: CLOSED Black parking lot status: 58.3% Airport at time 8: District status: Brown parking lot status: CLOSED Green parking lot status: CLOSED Black parking lot status: 58.3% Airport at time 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. </pre> ## Acknowledgement This laboratory assignment was developed by [Dr. Rob Hasker](https://faculty-web.msoe.edu/hasker/) and the CS1011 faculty. <div class="notetip"> See your professor's instructions for details on submission guidelines and due dates. </div>

Tuesday, 22-Oct-2019 10:36:28 CDT