2022年停车场管理系统java可用 .pdf
importjava.io.*; publicclass Method privateint intinput() throws IOException,NumberFormatException BufferedReader br=new BufferedReader(newInputStreamReader(System.in ); String str=br.readLine(); int i=Integer.parseInt(str); return i; private String stringinput() throws IOException BufferedReader br=new BufferedReader(newInputStreamReader(System.in ); String str=br.readLine(); return str; privateboolean between(int n,int min,int max) for( int i=min;i=max;i+) if(n=i) returntrue; returnfalse; privatevoid printerror() System.out .println( 输入错误!请重新输入! ); String sip() String str; while( true) try 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 12 页 - - - - - - - - - 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(n,min,max) this.printerror(); continue; break; return n; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 12 页 - - - - - - - - - publicclass Car String car_no; String state; Car() car_no=null; state=null; publicclass Stop Car data; intsize; Stop() data=new Car1; size=0; private Car peek() returndata size-1; privateboolean isFull() returnsize=data. length; private Car pop() size-; returndata size; void pop(int location,Passway p,Temp t) if(location=this. size) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 12 页 - - - - - - - - - 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(); for( 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(); data size=target; size+; target.state=target.car_no+ 号车位于停车场 +size+ 号位 ; System.out .println(target.car_no+ 号车进入停车场 +size+ 号位 ); boolean isIn(String s) if( size=0) returnfalse; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 12 页 - - - - - - - - - for( int i=0;isize;i+) if( datai.car_no.equals(s) returntrue; returnfalse; privatevoid stretch() Car newData=new Cardata . length*2; for( int i=0;idata . length;i+) newDatai=data i; data=newData; void print() for( int i=0;isize;i+) System.out .println(data i.state.toString(); publicclass Passway Car data; intsize; intfront; Passway() data=new Car1; size=0; front=0; boolean isEmpty() returnsize=0; privateboolean isFull() returnsize=data. length; public Car remove() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 12 页 - - - - - - - - - Car result=data front; front=( front+1)% data . length; size-; Passway t=new Passway(); for( int i=0;ithis. size;i+) t.add(this. data front+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) returnfalse; for( int i=0;isize;i+) if( this. data ( front+i)% data. length.car_no.equals(s) returntrue; returnfalse; privatevoid 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+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 12 页 - - - - - - - - - System.out .println(data( front+i)% data . length.state.toString(); publicclass Temp private Car data ; privateintsize; Temp() data=new Car1; size=0; boolean isEmpty() returnsize=0; Car peek() returndata size-1; privateboolean isFull() returnsize=data. length; Car pop() size-; returndata size; void push(Car target) if( this.isFull() stretch(); data size=target; size+; System.out .println(target.car_no+ 号车暂时离开停车场 ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 12 页 - - - - - - - - - target.state=target.car_no+ 号车暂时离开停车场 ; privatevoid stretch() Car newData=new Cardata . length*2; for( int i=0;idata . length;i+) newDatai=data i; data=newData; publicclass cms publicstaticvoid 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 .println(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+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 12 页 - - - - - - - - - System.out .println( 请输入停车位 +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( int n=1;n+) System.out .println( 请输入便道 +n+ 号位汽车的编号,键入$完结 ); String str01=null; while( true) str01=method.sip(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 12 页 - - - - - - - - - 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_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) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 12 页 - - - - - - - - - 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: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=method.iip(1,5); if(stop.sizei41) System.out .println( 此车位尚无汽车! ); else System.out .println(stop.data i41-1.state.toString(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 12 页 - - - - - - - - - elseif(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; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 12 页 - - - - - - - - -