oo-parking-lot

所属分类:编程语言基础
开发工具:Ruby
文件大小:0KB
下载次数:0
上传日期:2023-12-16 22:46:31
上 传 者sh-1993
说明:  面向对象的购物中心
(Object Oriented Mall)

文件列表:
lib/
spec/
.rspec
Gemfile
Gemfile.lock

# OO Parking Lot Short Description: Implement a parking allocation system for a new malling complex, the Object-Oriented Mall. The new parking system will pre-assign a slot for every vehicle coming into the complex. No vehicle can freely choose a parking slot and no vehicle is reserved or assigned a slot until they arrive at the entry point of the complex ## Unit test with RSPEC Install ``` bundle exec rspec ``` Run unit test ``` bundle exec rspec ``` ## Example 1: Large spots full ### Execution (lib/lot.rb): ``` lot = Lot.new lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[3], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[3], vehicle: LargeVehicle.new) lot.visualize_spots ``` ### Result: ``` L vehicle parked successfully from entrance A at spot no. 4 L vehicle parked successfully from entrance C at spot no. 7 L vehicle parked successfully from entrance B at spot no. 6 L vehicle parked successfully from entrance C at spot no. 5 L vehicle parked successfully from entrance C at spot no. 3 L vehicle parked successfully from entrance B at spot no. 2 L vehicle parked successfully from entrance C at spot no. 1 L vehicle parked successfully from entrance C at spot no. 0 Can't park L vehicle, no available spot!. From entrance C Spot Format: |Index,Spot Size,Availability(Y/N)| ============================================================================================ #|0 ,LP,N||1 ,LP,N||2 ,LP,N||3 ,LP,N||4 ,LP,N||5 ,LP,N||6 ,LP,N||7 ,LP,N||8 ,SP,Y||9 ,SP,Y|# ============================================================================================ #|10,SP,Y||11,SP,Y||12,SP,Y||13,SP,Y||14,SP,Y||15,SP,Y||16,SP,Y||17,SP,Y||18,SP,Y||19,SP,Y|# ============================================================================================ #|20,SP,Y||21,SP,Y||22,SP,Y||23,SP,Y||24,SP,Y||25,MP,Y||26,MP,Y||27,MP,Y||28,MP,Y||29,MP,Y|# ============================================================================================ #|30,MP,Y||31,MP,Y||32,MP,Y|# ============================================================================================ entrances: |4,A||10,B||19,C||30,C| -> Format |NearestSpot(Index),Name| total spots: 33 available spots: 25 ``` ### Conclusion: Our system manage to find the nearest suited spot in different entrances and notify until there is no large spots are available ## Example 2: Populate with different vehicle types ### Execution (lib/lot.rb): ``` lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: MediumVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: MediumVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[3], vehicle: MediumVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: MediumVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[0], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: MediumVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: SmallVehicle.new) # unpark some spot lot.unpark_vehicle(spot_no: 10) lot.unpark_vehicle(spot_no: 6) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: LargeVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: SmallVehicle.new) lot.park_vehicle(entrance: lot.parking_entrances[3], vehicle: MediumVehicle.new) lot.visualize_spots ``` ### Result: ``` S vehicle parked successfully from entrance A at spot no. 4 M vehicle parked successfully from entrance A at spot no. 3 L vehicle parked successfully from entrance A at spot no. 2 M vehicle parked successfully from entrance B at spot no. 7 S vehicle parked successfully from entrance B at spot no. 10 L vehicle parked successfully from entrance C at spot no. 6 S vehicle parked successfully from entrance C at spot no. 19 S vehicle parked successfully from entrance C at spot no. 18 M vehicle parked successfully from entrance C at spot no. 30 S vehicle parked successfully from entrance A at spot no. 1 M vehicle parked successfully from entrance A at spot no. 0 L vehicle parked successfully from entrance A at spot no. 5 M vehicle parked successfully from entrance B at spot no. 25 S vehicle parked successfully from entrance B at spot no. 9 Duration -> days: 2, hours: 0.8, total: 10020, fee: 10020 PHP Spot successfully unparked at spot no. 10 with spot_size: SP Duration -> days: 0, hours: 0.4, total: 40, fee: 40 PHP Spot successfully unparked at spot no. 6 with spot_size: LP L vehicle parked successfully from entrance C at spot no. 6 S vehicle parked successfully from entrance C at spot no. 17 S vehicle parked successfully from entrance C at spot no. 16 M vehicle parked successfully from entrance C at spot no. 29 Spot Format: |Index,SpotSize,Availability(Y/N)| ============================================================================================ #|0 ,LP,N||1 ,LP,N||2 ,LP,N||3 ,LP,N||4 ,LP,N||5 ,LP,N||6 ,LP,N||7 ,LP,N||8 ,SP,Y||9 ,SP,N|# ============================================================================================ #|10,SP,Y||11,SP,Y||12,SP,Y||13,SP,Y||14,SP,Y||15,SP,Y||16,SP,N||17,SP,N||18,SP,N||19,SP,N|# ============================================================================================ #|20,SP,Y||21,SP,Y||22,SP,Y||23,SP,Y||24,SP,Y||25,MP,N||26,MP,Y||27,MP,Y||28,MP,Y||29,MP,N|# ============================================================================================ #|30,MP,N||31,MP,Y||32,MP,Y|# ============================================================================================ entrances:|4,A||10,B||19,C||30,C| -> Format |NearestSpot(Index),Name| total spots: 33 available spots: 1 ``` ### Conclusion: Our system manage to find by populating with different vehicle types with some unparked slots and calculate the fee ## Example 3: Park, unpark and return before an hour ### Execution (lib/lot.rb): ``` # parked ex_vehicle_returned = SmallVehicle.new lot.park_vehicle(entrance: lot.parking_entrances[2], vehicle: ex_vehicle_returned) # unpark vehicle and return lot.unpark_vehicle(spot_no: ex_vehicle_returned.ticket.spot.spot_no) lot.park_vehicle(entrance: lot.parking_entrances[1], vehicle: ex_vehicle_returned) lot.unpark_vehicle(spot_no: ex_vehicle_returned.ticket.spot.spot_no) ``` ### Result: ``` S vehicle parked successfully from entrance C at spot no. 19 Duration -> days: 0, hours: 3.8, total: 140, fee: 140 PHP Spot successfully unparked at spot no. 19 with spot_size: SP S vehicle parked successfully from entrance B at spot no. 10 Duration -> days: 2, hours: 14.1, total: 10280, fee: 10140 PHP Spot successfully unparked at spot no. 10 with spot_size: SP ``` ### Conclusion: Vehicle leave the lot and return before an hour, the vehicle is charge at first leave and deducted the prevoius payment from the current payment ### Explaination: The total duration is 2 days and 14.1 hours at first leave vehicle pays the (0 day and 3.8 hrs - 140 PHP), the next time vehicle leaves it will deduct (previous fee - total amount) because the vehicle already pays the first one.

近期下载者

相关文件


收藏者