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.

  • 相关阅读:
    javascript-jquery对象的事件处理
    javascript-jquery对象的动画处理
    vue.config.js配置 移动端配置自适应rem响应
    vue封装axios
    js工具类
    git解决空文件夹无法提交
    vue的axios
    vue中axios跨域问题
    全局控制vue的依赖
    linux搭建php环境
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3410547.html
Copyright © 2011-2022 走看看