A parking garage in a busy metropolis contains a single lane that holds up to 7
ID: 3545144 • Letter: A
Question
A parking garage in a busy metropolis contains a single lane that holds up to 7 cars. There is only a single entrance/exit to the garage at one end of the lane. If a customer arrives to pick up a car that is not nearest the exit, all cars blocking its path are moved out, the customer's car is driven out, and the other cars are restored in the order they were in originally.
Your task is to write a Java class to model the parking garage. Your class should be named Garage and should include the following public methods:
? Garage(): a constructor to initialize an empty garage.
? Garage(String fileName): a constructor to initialize a garage and process the instructions contained in the file given as argument. The file is expected to contain a number of input lines. Each line contains either the letter a (arrival) or the letter d (departure), followed by a license plate number (6 characters). A single blank separates the one-letter code and the license plate number. Arrivals and departures should be processed as detailed in the method descriptions below. If the specified file does not exist, the constructor should initialize an empty garage.
? boolean arrival(String license): called to process the arrival of a car. When a car arrives, it enters the garage if there is room. If there is no room, the car must wait until there is room, and other incoming cars also wait on a first-come, first-serve basis. However, if a car arrives and the driver sees that there are five cars already waiting to enter the garage, the very disappointed driver decides to look for another garage. Return false if the driver leaves disappointed, true otherwise.
? int departure(String license): called to process the departure of a car. When a car leaves (and cars blocking its path are moved out and moved back into the garage), the method should return the number of cars that had to be moved out. When room becomes available, the car at the beginning of the waiting line
Explanation / Answer
no answers provided
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.