Problem
Solution
Lets start with the design.
Class diagram and classes in java to come soon
References
http://stackoverflow.com/questions/764933/amazon-interview-question-design-an-oo-parking-lot
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.
Solution
Lets start with the design.
class ParkingLot 1. ParkingLot keeps array of ParkingSpot 2. Separate array of vacant ParkingSpot 3. Separate array for HandiCappedDrivers, some x% 3. ParkingSpot FindVacantSpaceNearestEntrance() 4. IsParkingLotFull(), IsEmpty(), IsNormal() class ParkingSpot 1. distance from ParkingLot entrance 2. Take() - take the ParkingSpot 3. Vacate() - empty the ParkingSpot ParkingSpot has an Entrance. class HandicappedParkingSpot is a subclass of ParkingSpot. class RegularParkingSpot is a subclass of ParkingSpot. class CompactParkingSpot is a subclass of ParkingSpot. class Parker 1. ParkingSpot it occupies 2. Vehicle he has 3. park() - calls ParkingSpot.take() 4. unPark() - calls ParkingSpot.vacate() class Valet is a subclass of Parker 1. calls ParkingLot.FindVacantSpaceNearestEntrance(), which returns a ParkingSpot that can call ParkingLot.FindVacantSpaceNearestEntrance(), which returns a ParkingSpot. class HandiCappedParker is subclass of Parker class CompactParker a subclass of Parker class RegularParker a subclass of Parker class Vehicle 1. has number Parker calls Entrance.Entering() and Entrance.Exiting() and ParkingSpot notifies ParkingLot when it is taken or vacated so that ParkingLot can determine if it is full or not. If it is newly full or newly empty or newly not full or empty, it should change the ParkingLotSign.Full() or ParkingLotSign.Empty() or ParkingLotSign.Normal(). HandicappedParker could be a subclass of Parker and CompactParker a subclass of Parker and RegularParker a subclass of Parker. (might be overkill, actually.)
Class diagram and classes in java to come soon
References
http://stackoverflow.com/questions/764933/amazon-interview-question-design-an-oo-parking-lot
0 comments:
Post a Comment