您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 咨询培训 > 停车场管理系统(java)
importjava.io.*;publicclassMethod{privateintintinput()throwsIOException,NumberFormatException{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));Stringstr=br.readLine();inti=Integer.parseInt(str);returni;}privateStringstringinput()throwsIOException{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));Stringstr=br.readLine();returnstr;}privatebooleanbetween(intn,intmin,intmax){for(inti=min;i=max;i++)if(n==i)returntrue;returnfalse;}privatevoidprinterror(){System.out.println(输入错误!请重新输入!);}Stringsip(){Stringstr;while(true){try{str=this.stringinput();}catch(IOExceptione){this.printerror();continue;}break;}returnstr;}intiip(intmin,intmax){intn=0;while(true){try{n=this.intinput();}catch(IOExceptione){this.printerror();continue;}catch(NumberFormatExceptione){this.printerror();continue;}if(!this.between(n,min,max)){this.printerror();continue;}break;}returnn;}}publicclassCar{Stringcar_no;Stringstate;Car(){car_no=null;state=null;}}publicclassStop{Cardata[];intsize;Stop(){data=newCar[1];size=0;}privateCarpeek(){returndata[size-1];}privatebooleanisFull(){returnsize==data.length;}privateCarpop(){size--;returndata[size];}voidpop(intlocation,Passwayp,Tempt){if(location==this.size){System.out.println(this.peek().car_no+号车离开停车场);this.pop();}else{intf=this.size;for(inti=1;i=f-location;i++){t.push(this.peek());this.pop();}System.out.println(this.peek().car_no+号车离开停车场);this.pop();for(inti=0;!t.isEmpty();i++){this.push(t.peek());t.pop();}}if(!p.isEmpty()){this.push(p.data[p.front]);p.remove();}}voidpush(Cartarget){if(this.isFull())stretch();data[size]=target;size++;target.state=target.car_no+号车位于停车场+size+号位;System.out.println(target.car_no+号车进入停车场+size+号位);}booleanisIn(Strings){if(size==0)returnfalse;for(inti=0;isize;i++)if(data[i].car_no.equals(s))returntrue;returnfalse;}privatevoidstretch(){Car[]newData=newCar[data.length*2];for(inti=0;idata.length;i++)newData[i]=data[i];data=newData;}voidprint(){for(inti=0;isize;i++)System.out.println(data[i].state.toString());}}publicclassPassway{Car[]data;intsize;intfront;Passway(){data=newCar[1];size=0;front=0;}booleanisEmpty(){returnsize==0;}privatebooleanisFull(){returnsize==data.length;}publicCarremove(){Carresult=data[front];front=(front+1)%data.length;size--;Passwayt=newPassway();for(inti=0;ithis.size;i++)t.add(this.data[front+i]);returnresult;}voidadd(Cartarget){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+号位);}booleanisIn(Strings){if(size==0)returnfalse;for(inti=0;isize;i++)if(this.data[(front+i)%data.length].car_no.equals(s))returntrue;returnfalse;}privatevoidstretch(){CarnewData[]=newCar[data.length*2];for(inti=0;idata.length;i++)newData[i]=data[(front+i)%data.length];data=newData;front=0;}voidprint(){for(inti=0;isize;i++)System.out.println(data[(front+i)%data.length].state.toString());}}publicclassTemp{privateCar[]data;privateintsize;Temp(){data=newCar[1];size=0;}booleanisEmpty(){returnsize==0;}Carpeek(){returndata[size-1];}privatebooleanisFull(){returnsize==data.length;}Carpop(){size--;returndata[size];}voidpush(Cartarget){if(this.isFull())stretch();data[size]=target;size++;System.out.println(target.car_no+号车暂时离开停车场);target.state=target.car_no+号车暂时离开停车场;}privatevoidstretch(){Car[]newData=newCar[data.length*2];for(inti=0;idata.length;i++)newData[i]=data[i];data=newData;}}publicclasscms{publicstaticvoidmain(Stringargs[]){Stopstop=newStop();Passwaypassway=newPassway();Temptemp=newTemp();Methodmethod=newMethod();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:退出);intselect=method.iip(1,5);switch(select){case1:inti;Stopnewstop=newStop();Passwaynewpassway=newPassway();stop=newstop;passway=newpassway;for(i=1;i=5;i++){System.out.println(请输入停车位+i+号车位汽车的编号,键入$完结);Stringstr=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{Carc=newCar();c.car_no=str;stop.push(c);}}if(stop.size==5)for(intn=1;;n++){System.out.println(请输入便道+n+号位汽车的编号,键入$完结);Stringstr01=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{Carc=newCar();c.car_no=str01;passway.add(c);}}continue;case2:System.out.println(请输入待进汽车的编号:);Stringstr02=null;while(true){str02=method.sip();if(stop.isIn(str02)){System.out.println(此车已在停车场里,请重新输入!);continue;}if(passway.isIn(str02)){System.out.println(此车已在便道里,请重新输入!);continue;}break;}Carc=newCar();c.car_no=str02;if(stop.size5)stop.push(c);elsepassway.add(c);continue;case3:System.out.println(请输入待出汽车的停车位编号:);inti2;i2=method.iip(1,5);if(i2stop.size){System.out.println(此车位尚无汽车!);continue;}stop
本文标题:停车场管理系统(java)
链接地址:https://www.777doc.com/doc-2985087 .html