Loading...
Loading...
Loading...
A parking lot is built with n numbered slots, and the slots belong to it. A car parks in the lowest free slot and later leaves.
Write Slot (number and the parked car, or null) and ParkingLot, which creates its own Slot objects in its constructor and offers park, leave and status.
park CAR, leave CAR or status.PARKED CAR AT s, ALREADY CAR or FULL CAR; LEFT CAR FROM s or NOT FOUND CAR; status prints 1:CAR 2:- … on one line.Example
Input
3 7 park KA01 park KA02 leave KA01 park KA03 park KA02 park KA04 status
Output
PARKED KA01 AT 1 PARKED KA02 AT 2 LEFT KA01 FROM 1 PARKED KA03 AT 1 ALREADY KA02 PARKED KA04 AT 3 1:KA03 2:KA02 3:KA04
KA03 takes slot 1, freed by KA01; KA04 finds every slot taken.
Try the problem first. Open one hint at a time.
In the constructor: slots[i] = new Slot(i + 1); for every i. main passes only n.
Check "already parked" before looking for a free slot.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor