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.

  • 相关阅读:
    python基础27 -----python进程终结篇-----IO模型
    python基础26 -----python进程及协成
    python基础25 -----python高级用法
    python基础24 -----python中的各种锁
    python基础23 -----进程和线程
    Leetcode:5. Longest Palindromic Substring
    Leetcode: 3. Longest Substring Without Repeating Characters
    4. Median of Two Sorted Arrays
    Leetcode:445. Add Two Numbers II
    Leetcode: 43. Multiply Strings
  • 原文地址:https://www.cnblogs.com/reynold-lei/p/3410547.html
Copyright © 2011-2022 走看看