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();

           }

       }

}

amazon 设计 6 parking lot,布布扣,bubuko.com

时间: 2024-11-03 22:05:39

amazon 设计 6 parking lot的相关文章

amazon.设计1. tic tac toe

//不觉中 已经全力找工作好久好久了.大概有1年半了.身心疲惫,不要放弃.曙光快来了. 1.tic tac toe //http://www.ntu.edu.sg/home/ehchua/programming/java/JavaGame_TicTacToe.html 类似相关棋牌坐标对战游戏 一通百通 /** * Enumerations for the various states of the game */ public enum GameState { // to save as "G

amazon 设计 11 chess

1 public class ChessPieceTurn { }; 2 public class GameManager { 3 void processTurn(PlayerBase player) { }; 4 boolean acceptTurn(ChessPieceTurn turn) { return true; }; 5 Position currentPosition; 6 } 7 8 public abstract class PlayerBase { 9 public abs

amazon 设计 7 genial card game

package card; public class Game implements Runnable{ int numPlayers; int startNumber; //players and hands seperate so players can't change their cards Player player[] = new Player[numPlayers]; Hand hands[] = new Hand[numPlayers]; Card topCard; Deck d

amazon 设计 10 puzzle.

class Edge { enum Type { inner, outer, flat } Piece parent; Type type; boolean fitsWith(Edge type) { }; // Inners & outer fit together. } class Piece { Edge left, right, top, bottom; // 90, 180, etc Orientation solvedOrientation = 90; } class Puzzle

amazon 设计 13 drawboard

public class Drawboard extends JFrame{ Graphics g; public static void main(String[] args){ Drawboard d = new Drawboard(); d.showUI(); } public void showUI(){ Graphics g ; this.setTitle("画图板"); this.setSize(600,600); this.setDefaultCloseOperation

amazon 设计 5 hotel and restaurant reservation system

there I write down the restaurant system. public class TimeSpan { Date date; String start; String end; } public class Table { int tableid; String type; HashMap<Date,HashMap<String,String>> reserved; public boolean isFitToRequest(Request ts){ r

分布式系统(Distributed System)资料

这个资料关于分布式系统资料,作者写的太好了.拿过来以备用 网址:https://github.com/ty4z2008/Qix/blob/master/ds.md 希望转载的朋友,你可以不用联系我.但是一定要保留原文链接,因为这个项目还在继续也在不定期更新.希望看到文章的朋友能够学到更多. <Reconfigurable Distributed Storage for Dynamic Networks> 介绍:这是一篇介绍在动态网络里面实现分布式系统重构的paper.论文的作者(导师)是MIT

从事分布式系统,计算,hadoop

作者:廖君链接:https://www.zhihu.com/question/19868791/answer/88873783来源:知乎 分布式系统(Distributed System)资料 <Reconfigurable Distributed Storage for Dynamic Networks> 介绍:这是一篇介绍在动态网络里面实现分布式系统重构的paper.论文的作者(导师)是MIT读博的时候是做分布式系统的研究的,现在在NUS带学生,不仅仅是分布式系统,还有无线网络.如果感兴趣

想从事分布式系统,计算,hadoop等方面,需要哪些基础,推荐哪些书籍?--转自知乎

作者:廖君链接:https://www.zhihu.com/question/19868791/answer/88873783来源:知乎 分布式系统(Distributed System)资料 <Reconfigurable Distributed Storage for Dynamic Networks> 介绍:这是一篇介绍在动态网络里面实现分布式系统重构的paper.论文的作者(导师)是MIT读博的时候是做分布式系统的研究的,现在在NUS带学生,不仅仅是分布式系统,还有无线网络.如果感兴趣