停车场管理系统java.docx
《停车场管理系统java.docx》由会员分享,可在线阅读,更多相关《停车场管理系统java.docx(17页珍藏版)》请在冰豆网上搜索。
![停车场管理系统java.docx](https://file1.bdocx.com/fileroot1/2023-7/25/8e72ce3e-7873-4e96-9e3a-6d93fdce0a69/8e72ce3e-7873-4e96-9e3a-6d93fdce0a691.gif)
停车场管理系统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;iif(data[i].car_no.equals(s))
returntrue;
returnfalse;
}
privatevoidstretch()
{
Car[]newData=newCar[data.length*2];
for(inti=0;inewData[i]=data[i];
data=newData;
}
voidprint()
{
for(inti=0;iSystem.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;it.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;iif(this.data[(front+i)%data.length].car_no.equals(s))
returntrue;
returnfalse;
}
privatevoidstretch()
{
CarnewData[]=newCar[data.length*2];
for(inti=0;inewData[i]=data[(front+i)%data.length];
data=newData;
front=0;
}
voidprint()
{
for(inti=0;iSystem.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;inewData[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.size<5)
stop.push(c);
else
passway.add(c);
continue;
case3:
System.out.println("请输入待出汽车的停车位编号:
");
inti2;
i2=method.iip(1,5);
if(i2>stop.size)
{
System.out.println("此车位尚无汽车!
");
continue;
}
stop.pop(i2,passway,temp);
continue;
case4:
System.out.println("请选择查询区域:
");
System.out.println("1:
停车场");
System.out.println("2:
便道");
System.out.println("3:
打印全部");
inti4=method.iip(1,3);
if(i4==1)
{
System.out.println("请输入待查询停车场车位编号:
");
inti41=method.iip(1,5);
if(stop.sizeSystem.out.println("此车位尚无汽车!
");
else
System.out.println(stop.data[i41-1].state.toString());
}
else
if(i4==2)
{
System.out.println("请输入待查询便道车位编号:
");
inti42=method.iip(1,100);
if(passway.sizeSystem.out.println("此车位尚无汽车!
");
else
{
intii=(i42-1+passway.front)%passway.data.length;
System.out.println(passway.data[ii].state.toString());
}
}
else
{
stop.print();
passway.print();
}
continue;
case5:
System.out.println("欢迎再次使用!
");
}
break;
}
}
}