/** 取车 */ public boolean drawOut(ParkCard parkCard, Car car) throws Exception { boolean b = false; if (parkCard == null) { System.out.println("无效的停车卡!"); return false; } if (car == null) { System.out.println("车辆信息无效!"); return false; } if (this.isAllParkEmpty()) { System.out.println("非法的取车请求:当前所有停车场均无车!"); return false; } String cardId = parkCard.getCardId(); ParkCard readyCard = this.parkCardMap.get(cardId); if (readyCard == null) { System.out.println("无效的停车卡!"); return false; } Car readyCar = readyCard.getCar(); if (!car.getNumber().equalsIgnoreCase(readyCar.getNumber())) { System.out.println("车卡不一致,不允许取车!"); return false; } Park readyPark = readyCard.getPark(); this.parkCardMap.remove(cardId); int parkSpaceNum = readyPark.getSpaceNum(); readyPark.setSpaceNum(parkSpaceNum + 1); System.out.println("车牌号为:" + car.getNumber() + "已成功从[" + readyPark.getParkName() + "]取出!"); return b; }
/** * 停车 * * @param car * @return * @throws Exception */ public ParkCard park(Car car) throws Exception { ParkCard parkCard = null; // 分配停车场 Park park = this.distributePark(); if (park == null) { System.out.println("对不起,所有停车场都没有空闲停车位!"); } else { // 发卡停车 parkCard = new ParkCard(park, car); this.parkCardMap.put(parkCard.getCardId(), parkCard); int parkSpaceNum = park.getSpaceNum(); park.setSpaceNum(parkSpaceNum - 1); System.out.println("车牌号为:" + car.getNumber() + "已成功停车至[" + park.getParkName() + "]!"); this.displaySpaceNum(); } return parkCard; }