zoukankan      html  css  js  c++  java
  • 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.

    Here is a quick start to get the gears turning...

    ParkingLot is a class.

    ParkingSpace is a class.

    ParkingSpace has an Entrance.

    Entrance has a location or more specifically, distance from Entrance.

    ParkingLotSign is a class.

    ParkingLot has a ParkingLotSign.

    ParkingLot has a finite number of ParkingSpaces.

    HandicappedParkingSpace is a subclass of ParkingSpace.

    RegularParkingSpace is a subclass of ParkingSpace.

    CompactParkingSpace is a subclass of ParkingSpace.

    ParkingLot keeps array of ParkingSpaces, and a separate array of vacant ParkingSpaces in order of distance from its Entrance.

    ParkingLotSign can be told to display "full", or "empty", or "blank/normal/partially occupied" by calling .Full(), .Empty() or .Normal()

    Parker is a class.

    Parker can Park().

    Parker can Unpark().

    Valet is a subclass of Parker that can call ParkingLot.FindVacantSpaceNearestEntrance(), which returns a ParkingSpace.

    Parker has a ParkingSpace.

    Parker can call ParkingSpace.Take() and ParkingSpace.Vacate().

    Parker calls Entrance.Entering() and Entrance.Exiting() and ParkingSpace 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.)

    In this solution, it is possible that Parker should be renamed to be Car.

  • 相关阅读:
    初识Qgis
    特征向量与特征值及其应用
    练习 |委托方在每个月重复委案率
    Redis命令总结
    sharepoint2013 Restore-SPSite 报错,采用数据库还原
    MySql定期存档数据
    PostgreSQL的 fdw 跨库使用
    java&c# dec 加密,通用
    TypeScript
    CentOS挂载windows共享文件夹
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3410547.html
Copyright © 2011-2022 走看看