weight = 19

Overview

For this lab, you will revise your Lab 8 solution by introducing arrays of ParkingLots in the District class.

Resources

Assignment

The previous version of the District class you delivered was limited to districts with three parking lots. This was an artificial limit, and you have been contracted to revise the code to support up to twenty parking lots per district. You are to replace the lot1, lot2, and lot3 instance variables in District by an array, lots, of ParkingLot items. The array is to support up to 20 parking lots. You will introduce a variable numLots to track the number of parking lots currently in use. In addition, you will make a small modification to ParkingLot as described below.

It is recommended that you create a new project and copy your lab 8 implmentations of the ParkingLot and District classes to the new project. Begin by fixing any known issues with your lab 8 submission. In place of the ParkingDriver.java file used in lab 8, you will need to use the ParkingLotsDriver.java.

The following diagram shows the revised API that you are to implement. Detail on each change is given below.

ParkingLot
+CLOSED_THRESHOLD: double {readOnly} = 80.0
-name: String {readOnly}
+ParkingLot(name: String, capacity: int)
+ParkingLot(capacity: int)
+getMinutesClosed(): int
+getName(): String
+getNumberOfSpotsRemaining(): int
+getPercentFull(): double
+isClosed(): boolean
+markVehicleEntry(timestamp: int): void
+markVehicleExit(timestamp: int): void
+toString(): String
District
-lots: ParkingLot[]
+MAX_LOTS: int {readOnly} =20
-numLots: int
+District()
+addLot(name: String, capacity: int): int
+getLot(index: int): ParkingLot
+getMinutesClosed(): int
+getNumberOfSpotsRemaining(): int
+isClosed(): boolean
+markVehicleEntry(lotNumber: int, timestamp: int): void
+markVehicleExit(lotNumber: int, timestamp: int): void
+toString(): String

Changes to ParkingLot

You will need to make the following changes to your ParkingLot class:

Having toString() is good practice because it allows the client code to print other places besides System.out.

Changes to District

Most of the changes are to District, but you might notice that the parameters and return types for existing methods do not change. Specifically:

    public District() {
        lots = new ParkingLot[MAX_LOTS];
    }
        int newIndex = numLots;
        if(newIndex<MAX_LOTS) {
            lots[newIndex] = new ParkingLot(name, capacity);
            numLots++;
        }
        // return the index of the new lot or -1 if the lot was not added.
        return newIndex<MAX_LOTS ? newIndex : -1;
District status:
  Status for purple parking lot: 8 vehicles (CLOSED)
  Status for gold parking lot: 20 vehicles (33.3%)

Here you should call ParkingLot.toString() for each line, prepending two spaces and appending "\n" for the newline. There should be a newline at the end of each line including the last.

Testing and Sample Output

The ParkingLotsDriver exercises most of your code. The output is given below, but remember that having slightly different numbers may be okay and that matching this output does not automatically mean your solution is correct.

Testing Small Lot...
Status for Blacktop parking lot: 0 vehicles (0%)
Finished Testing Small Lot

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

More Complete Test of Parking Lot...
Testing ParkingLot
Status for test parking lot: 3 vehicles (75%)
Status for test parking lot: 4 vehicles (CLOSED)
Status for test parking lot: 2 vehicles (50%)
Status for test parking lot: 0 vehicles (0%)
Final status: Status for test parking lot: 0 vehicles (0%)
Finished More Complete Test of Parking Lot

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

Testing Tiny District...
Tiny District status:
  Status for Red parking lot: 0 vehicles (0%)
  Status for Green parking lot: 0 vehicles (0%)
  Status for Blue parking lot: 0 vehicles (0%)

District status:
  Status for Red parking lot: 1 vehicles (CLOSED)
  Status for Green parking lot: 0 vehicles (0%)
  Status for Blue parking lot: 2 vehicles (CLOSED)

Final Tiny District status:
  Status for Red parking lot: 0 vehicles (0%)
  Status for Green parking lot: 1 vehicles (CLOSED)
  Status for Blue parking lot: 2 vehicles (CLOSED)

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

Finished Testing Normal District...
Airport at timestamp 7:
District status:
  Status for Brown parking lot: 7 vehicles (70%)
  Status for Green parking lot: 14 vehicles (CLOSED)
  Status for Black parking lot: 7 vehicles (58.3%)

Airport at timestamp 8:
District status:
  Status for Brown parking lot: 8 vehicles (CLOSED)
  Status for Green parking lot: 14 vehicles (CLOSED)
  Status for Black parking lot: 7 vehicles (58.3%)

Airport at timestamp 10:
District status:
  Status for Brown parking lot: 8 vehicles (CLOSED)
  Status for Green parking lot: 14 vehicles (CLOSED)
  Status for Black parking lot: 10 vehicles (CLOSED)

Finished Testing Normal District

Finished Testing Heavily Used District...
At end of day, all lots closed 42 min.
Final District status:
  Status for Pink parking lot: 17 vehicles (68%)
  Status for Blue parking lot: 28 vehicles (CLOSED)
  Status for Gray parking lot: 2 vehicles (20%)

Finished Testing Heavily Used District

All tests finished.

Acknowledgement

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

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