问题描述
设计一个OO停车场.它将具有哪些类和功能.应该说满了,空了,还可以找到代客泊车的地方.该停车场有3种不同类型的停车位:普通,残疾人和紧凑型.
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是一门课.
ParkingLot is a class.
ParkingSpace是一门课.
ParkingSpace is a class.
ParkingSpace有一个入口.
ParkingSpace has an Entrance.
入口具有一个位置,或更确切地说,是距入口的距离.
Entrance has a location or more specifically, distance from Entrance.
ParkingLotSign是一个类.
ParkingLotSign is a class.
ParkingLot有一个ParkingLotSign.
ParkingLot has a ParkingLotSign.
ParkingLot具有有限数量的ParkingSpaces.
ParkingLot has a finite number of ParkingSpaces.
HandicappedParkingSpace是ParkingSpace的子类.
HandicappedParkingSpace is a subclass of ParkingSpace.
RegularParkingSpace是ParkingSpace的子类.
RegularParkingSpace is a subclass of ParkingSpace.
CompactParkingSpace是ParkingSpace的子类.
CompactParkingSpace is a subclass of ParkingSpace.
ParkingLot会保留一系列的ParkingSpace,并按照距其入口的距离的顺序排列一个单独的闲置ParkingSpace.
ParkingLot keeps array of ParkingSpaces, and a separate array of vacant ParkingSpaces in order of distance from its Entrance.
通过调用.Full()、. Empty()或.Normal(),可以告诉ParkingLotSign显示满",空"或空白/正常/部分占用"
ParkingLotSign can be told to display "full", or "empty", or "blank/normal/partially occupied" by calling .Full(), .Empty() or .Normal()
Parker是一堂课.
Parker is a class.
Parker可以停车().
Parker can Park().
Parker可以取消停车().
Parker can Unpark().
代客泊车是Parker的子类,可以调用ParkingLot.FindVacantSpaceNearestEntrance(),并返回一个ParkingSpace.
Valet is a subclass of Parker that can call ParkingLot.FindVacantSpaceNearestEntrance(), which returns a ParkingSpace.
Parker有一个ParkingSpace.
Parker has a ParkingSpace.
Parker可以调用ParkingSpace.Take()和ParkingSpace.Vacate().
Parker can call ParkingSpace.Take() and ParkingSpace.Vacate().
Parker调用Entry.Entering()和Entry.Exiting(),ParkingSpace会在ParkingLot被占用或腾空时通知ParkingLot,以便ParkingLot可以确定其是否已满.如果它是新装满或新装满或新装满或装满的,则应更改ParkingLotSign.Full()或ParkingLotSign.Empty()或ParkingLotSign.Normal().
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可以是Parker的子类,CompactParker可以是Parker的子类,RegularParker可以是Parker的子类. (实际上可能是过大的杀伤力.)
HandicappedParker could be a subclass of Parker and CompactParker a subclass of Parker and RegularParker a subclass of Parker. (might be overkill, actually.)
在此解决方案中,有可能应该将Parker重命名为Car.
In this solution, it is possible that Parker should be renamed to be Car.
这篇关于亚马逊采访问题:设计一个OO停车场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!