1、停车场管理系统javaimport java.io.*;public class Method private int intinput() throws IOException,NumberFormatException BufferedReader br=new BufferedReader(new InputStreamReader(System.in); String str=br.readLine(); int i=Integer.parseInt(str); return i; private String stringinput() throws IOException Buff
2、eredReader br=new BufferedReader(new InputStreamReader(System.in); String str=br.readLine(); return str; private boolean between(int n,int min,int max) for(int i=min;i=max;i+) if(n=i) return true; return false; private void printerror() System.out.println(输入错误!请重新输入!); String sip() String str; while
3、(true) try str=this.stringinput(); catch(IOException e) this.printerror(); continue; break; return str; int iip(int min,int max) int n=0; while(true) try n=this.intinput(); catch(IOException e) this.printerror(); continue; catch(NumberFormatException e) this.printerror(); continue; if(!this.between(
4、n,min,max) this.printerror(); continue; break; return n; public class Car String car_no; String state; Car() car_no=null; state=null; public class Stop Car data; int size; Stop() data=new Car1; size=0; private Car peek() return datasize-1; private boolean isFull() return size=data.length; private Ca
5、r pop() size-; return datasize; void pop(int location,Passway p,Temp t) if(location=this.size) System.out.println(this.peek().car_no+号车离开停车场); this.pop(); else int f=this.size; for(int i=1;i=f-location;i+) t.push(this.peek(); this.pop(); System.out.println(this.peek().car_no+号车离开停车场); this.pop(); fo
6、r(int i=0;!t.isEmpty();i+) this.push(t.peek(); t.pop(); if(!p.isEmpty() this.push(p.datap.front); p.remove(); void push(Car target) if(this.isFull() stretch(); datasize=target; size+; target.state=target.car_no+号车位于停车场+size+号位; System.out.println(target.car_no+号车进入停车场+size+号位); boolean isIn(String s
7、) if(size=0) return false; for(int i=0;isize;i+) if(datai.car_no.equals(s) return true; return false; private void stretch() Car newData=new Cardata.length*2; for(int i=0;idata.length;i+) newDatai=datai; data=newData; void print() for(int i=0;isize;i+) System.out.println(datai.state.toString(); publ
8、ic class Passway Car data; int size; int front; Passway() data=new Car1; size=0; front=0; boolean isEmpty() return size=0; private boolean isFull() return size=data.length; public Car remove() Car result=datafront; front=(front+1)%data.length; size-; Passway t=new Passway(); for(int i=0;ithis.size;i
9、+) t.add(this.datafront+i); return result; void add(Car target) if(this.isFull() this.stretch(); data(front+size)%data.length=target; size+; target.state=target.car_no+号车位于便道+size+号位; System.out.println(target.car_no+号车进入便道+size+号位); boolean isIn(String s) if(size=0) return false; for(int i=0;isize;
10、i+) if(this.data(front+i)%data.length.car_no.equals(s) return true; return false; private void stretch() Car newData=new Cardata.length*2; for(int i=0;idata.length;i+) newDatai=data(front+i)%data.length; data=newData; front=0; void print() for(int i=0;isize;i+) System.out.println(data(front+i)%data.
11、length.state.toString(); public class Temp private Car data; private int size; Temp() data=new Car1; size=0; boolean isEmpty() return size=0; Car peek() return datasize-1; private boolean isFull() return size=data.length; Car pop() size-; return datasize; void push(Car target) if(this.isFull() stret
12、ch(); datasize=target; size+; System.out.println(target.car_no+号车暂时离开停车场); target.state=target.car_no+号车暂时离开停车场; private void stretch() Car newData=new Cardata.length*2; for(int i=0;idata.length;i+) newDatai=datai; data=newData; public class cms public static void main(String args) Stop stop=new Sto
13、p(); Passway passway=new Passway(); Temp temp=new Temp(); Method method=new Method(); System.out.println(欢迎使用停车场管理系统!); while(true) System.out.println(请选择操作); System.out.println(1: 初始化); System.out.println(2:进车); System.out.println(3:出车); System.out.println(4:查询); System.out.println(5:退出); int selec
14、t=method.iip(1,5); switch(select) case 1:int i; Stop newstop=new Stop(); Passway newpassway=new Passway(); stop=newstop; passway=newpassway; for(i=1;i=5;i+) System.out.println(请输入停车位+i+号车位汽车的编号,键入$完结); String str=null; while(true) str=method.sip(); if(stop.isIn(str) System.out.println(此车已在停车场里,请重新输入
15、!); continue; if(passway.isIn(str) System.out.println(此车已在便道里,请重新输入!); continue; break; if(str.equals($) break; else Car c=new Car(); c.car_no=str; stop.push(c); if(stop.size=5) for(int n=1;n+) System.out.println(请输入便道+n+号位汽车的编号,键入$完结); String str01=null; while(true) str01=method.sip(); if(stop.isIn
16、(str01) System.out.println(此车已在停车场里,请重新输入!); continue; if(passway.isIn(str01) System.out.println(此车已在便道里,请重新输入!); continue; break; if(str01.equals($) break; else Car c=new Car(); c.car_no=str01; passway.add(c); continue; case 2:System.out.println(请输入待进汽车的编号:); String str02=null; while(true) str02=me
17、thod.sip(); if(stop.isIn(str02) System.out.println(此车已在停车场里,请重新输入!); continue; if(passway.isIn(str02) System.out.println(此车已在便道里,请重新输入!); continue; break; Car c=new Car(); c.car_no=str02; if(stop.sizestop.size) System.out.println(此车位尚无汽车!); continue; stop.pop(i2, passway, temp); continue; case 4:Sys
18、tem.out.println(请选择查询区域:); System.out.println(1:停车场); System.out.println(2:便道); System.out.println(3:打印全部); int i4=method.iip(1,3); if(i4=1) System.out.println(请输入待查询停车场车位编号:); int i41=method.iip(1,5); if(stop.sizei41) System.out.println(此车位尚无汽车!); else System.out.println(stop.datai41-1.state.toStri
19、ng(); else if(i4=2) System.out.println(请输入待查询便道车位编号:); int i42=method.iip(1, 100); if(passway.sizei42) System.out.println(此车位尚无汽车!); else int ii=(i42-1+passway.front)%passway.data.length; System.out.println(passway.dataii.state.toString(); else stop.print(); passway.print(); continue; case 5:System.out.println(欢迎再次使用!); break;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1