1、import java.io.*;public class Methodprivate int intinput() throws IOException,NumberFormatExceptionBufferedReader br=new BufferedReader(new InputStreamReader(System.in);String str=br.readLine();int i=Integer.parseInt(str);return i;private String stringinput() throws IOExceptionBufferedReader br=new
2、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(true)trystr=this.stringinput(
3、);catch(IOException e)this.printerror();continue;break;return str;int iip(int min,int max)int n=0;while(true)tryn=this.intinput();catch(IOException e) this.printerror(); continue; catch(NumberFormatException e) this.printerror(); continue; if(!this.between(n,min,max) this.printerror(); continue; bre
4、ak;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 Car pop()size-;return datasize;void pop(int location,Passway
5、p,Temp t) if(location=this.size)System.out.println(this.peek().car_no+号车离开停车场);this.pop();elseint 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();for(int i=0;!t.isEmpty();i+)this.push(t.peek();t.pop();if(!p.isEmpty() thi
6、s.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)if(size=0)return false;for(int i=0;isize;i+)if(datai.car_no.equals(s)return true;ret
7、urn 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();public class Passway Car data;int size;int front;Passway()data=new Car1;size=0;front=0;boolean isEmpty()
8、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+)t.add(this.datafront+i);return result;void add(Car target)if(this.isFull()this.stretch();data(front+size)%data.le
9、ngth=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;i+)if(this.data(front+i)%data.length.car_no.equals(s)return true;return false;private void stretch()Car newData=new Cardata.leng
10、th*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.length.state.toString();public class Temp private Car data;private int size;Temp()data=new Car1;size=0;boolean isEmpty()return size=0;Car pe
11、ek()return datasize-1;private boolean isFull()return size=data.length;Car pop()size-;return datasize;void push(Car target)if(this.isFull()stretch();datasize=target;size+;System.out.println(target.car_no+号车临时离开停车场);target.state=target.car_no+号车临时离开停车场;private void stretch()Car newData=new Cardata.len
12、gth*2;for(int i=0;idata.length;i+)newDatai=datai;data=newData;public class cmspublic static void main(String args)Stop stop=new Stop();Passway passway=new Passway();Temp temp=new Temp();Method method=new Method();System.out.println(欢迎使用停车场管理系统!);while(true)System.out.println(请选择操作);System.out.printl
13、n(1: 初始化);System.out.println(2:进车);System.out.println(3:出车);System.out.println(4:查询);System.out.println(5:退出);int select=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(请输入停车位+
14、i+号车位汽车编号,键入$完结); String str=null; while(true) str=method.sip(); if(stop.isIn(str) System.out.println(此车已在停车场里,请重新输入!); 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(in
15、t n=1;n+) System.out.println(请输入便道+n+号位汽车编号,键入$完结); String str01=null; while(true) str01=method.sip(); if(stop.isIn(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_
16、no=str01; passway.add(c); continue;case 2:System.out.println(请输入待进汽车编号:); String str02=null; while(true) str02=method.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;
17、 if(stop.sizestop.size) System.out.println(此车位尚无汽车!); continue; stop.pop(i2, passway, temp); continue;case 4:System.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=met
18、hod.iip(1,5); if(stop.sizei41) System.out.println(此车位尚无汽车!); else System.out.println(stop.datai41-1.state.toString(); 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;