我是靠谱客的博主 忧伤苗条,最近开发中收集的这篇文章主要介绍amazon 设计 6 parking lot,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

public abstract class Vehicle {
protected ParkingSpace pSpace;
public abstract boolean park(ParkingLot pLot);
public boolean unpark(ParkingLot pLot)P{
if(pSpace!=null){
pLot.reclaimFreeSpace(pSpace);
return true;
}
return false;
}
}
public class Cars extends Vehicle{
@Override
public boolean park(ParkingLot pLot) {
if( (pSpace = pLot.allocateFreeSpace(ParkingSpace.ParkingSpaceType.CAR)) ==null)
return true;
else
return false;
}
}
public class Motorbike extends Vehicle{
@Override
public boolean park(ParkingLot pLot) {
if( (pSpace = pLot.allocateFreeSpace(ParkingSpace.ParkingSpaceType.MOTOBIKE)) ==null)
return true;
else
return false;
}
}
public class HandicappedCars extends Vehicle{
@Override
public boolean park(ParkingLot pLot) {
if( (pSpace = pLot.allocateFreeSpace(ParkingSpace.ParkingSpaceType.HANDICAPPED)) ==null)
return true;
else
return false;
}
}
import java.sql.Time;
import java.util.GregorianCalendar;
public class ParkingSpace {
public enum ParkingSpaceType
{
MOTOBIKE, CAR, HANDICAPPED;
}
private int id;
private ParkingSpaceType pSpaceType;
private ParkingMeter meter;
public ParkingSpace(int id, ParkingSpaceType pspaceType)
{
super();
this.id = id;
this.pSpaceType = pspaceType;
}
public int getId()
{
return id;
}
public void setStart()
{
meter.start = new GregorianCalendar();
}
public void setEnd()
{
meter.end = new GregorianCalendar();
}
public ParkingSpaceType getpSpaceType(){
return pSpaceType;
}
private class ParkingMeter{
public GregorianCalendar start;
public GregorianCalendar end;
}
public float getFee()
{
return perm.getFee(meter.start, meter.end);
}
}
import java.util.List;
import parking.ParkingSpace.ParkingSpaceType;
public class ParkingLot {
private List<ParkingSpace> freeRegularSpace;
private List<ParkingSpace> freeCompactSpace;
private List<ParkingSpace> freeHandicappedSpace;
public ParkingLot(){};
public ParkingSpace allocateFreeSpace(ParkingSpaceType pSpaceType) throws Exception{
ParkingSpace pSpace = null;
switch(pSpaceType)
{
case MOTOBIKE:
if(freeRegularSpace.size()==0)
return null;
pSpace = freeRegularSpace.remove(0);
pSpace.setStart();
break;
case HANDICAPPED:
if(freeHandicappedSpace.size()==0)
return null;
pSpace = freeHandicappedSpace.remove(0);
pSpace.setStart();
break;
case CAR:
if(freeCompactSpace.size()==0)
return null;
pSpace = freeCompactSpace.remove(0);
pSpace.setStart();
break;
default:
throw new Exception("Invalid String");
}
public float reclainFreeSpace(ParkingSpace Space){
Space.setEnd();
switch(Space.getpSpaceType()){
case MOTOBIKE:
freeRegularSpace.add(Space);
break;
case CAR:
freeCompactSpace.add(Space);
break;
case HANDICAPPED:
freeHandicappedSpace.add(Space);
break;
default:
break;
}
return Space.getFee();
}
}
}

 

转载于:https://www.cnblogs.com/leetcode/p/3889233.html

最后

以上就是忧伤苗条为你收集整理的amazon 设计 6 parking lot的全部内容,希望文章能够帮你解决amazon 设计 6 parking lot所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部