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. ## 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. <figure>[<img src="parkingUMLclass.jpg" />](parkingUMLclass.jpg)</figure> ### Additional Notes on `ParkingLot` * 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. * Parking lots have colors. To simplify testing, `ParkingLot` defaults the color to `"test"` when no color is specified. * The method `vehiclesInLot` returns the number of vehicles in the lot at any one time. * The method `isClosed` returns whether or not a lot is closed because the number of vehicles in it is 80% of the number of spaces in the lot. 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. However, you do not need to handle the case where the number of vehicles is greater than the lot capacity. * Create a class constant `CLOSED_THRESHOLD` for the 80% threshold. Use this constant in your code so that it would be easy to support changes in the policy. * The method `closedMinutes` returns the number of minutes during which the lot is 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 `displayStatus` prints the color of the lot and the percentage of the lot that is occupied. If the percentage is at or above the threshold, display "CLOSED". 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` An initial version of `District.java` is being given to you. 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` 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> ### Creating the Project Do the following to set up your IntelliJ project: 1. Download the file [lab8.zip](lab8.zip) and save it in a convenient location on your computer. (Depending on your browser, you may need to do a right click to save the file.) 2. Extract all files from lab8.zip into a **lab8** folder. 3. Start IntelliJ and select **File > Open...** Browse to the folder that contains `lab8.iml` (which should be a folder with the IntelliJ icon on it) and click on **OK**. You can now browse the source files. Both `District` and `ParkingDriver` will contain a number of error messages because you have not yet written the methods for `ParkingLot`. The starting point for the lab is to add the appropriate stubs to `ParkingLot` so that the code does compile. If you are the sort of person that likes to drive down the road while texting and smoking a cigarette, you will now try to write all of the code in one big batch. A reasonable alternative is to edit `ParkingDriver.main()` and comment out everything but the call to `testSmallLot()`. Get this part working before attempting to test the rest of the system. ### 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> blacktop parking lot status: CLOSED Tiny district: red parking lot status: CLOSED green parking lot status: 0% blue parking lot status: CLOSED Lots were closed for 3 min. in tiny district. Testing ParkingLot test parking lot status: 75% test parking lot status: CLOSED test parking lot status: 50% test parking lot status: 0% Airport at time 7: brown parking lot status: 70% green parking lot status: CLOSED black parking lot status: 58.3% Airport at time 8: brown parking lot status: CLOSED green parking lot status: CLOSED black parking lot status: 58.3% Airport at time 10: brown parking lot status: CLOSED green parking lot status: CLOSED black parking lot status: CLOSED Testing heavier usage. At end of day, all lots closed 42 min. pink parking lot status: 68% blue parking lot status: CLOSED gray parking lot status: 20% All tests finished. </pre> ## Lab Deliverables <div class="notetip">See your professor's instructions for details on submission guidelines and due dates. <center> See Prof. Jones for instructions<br /> See Dr. Retert for instructions<br /> Dr. Taylor's class: submit using the form below<br /> See Dr. Thomas for instructions </center> If you have any questions, consult your instructor.</div> ## Acknowledgement This laboratory assignment was developed by [Dr. Rob Hasker](https://faculty-web.msoe.edu/hasker/).

Thursday, 19-Oct-2017 16:15:05 EDT