java停车场管理系统.docx
《java停车场管理系统.docx》由会员分享,可在线阅读,更多相关《java停车场管理系统.docx(13页珍藏版)》请在冰豆网上搜索。
java停车场管理系统
java停车场管理系统
本程序为word格式,下载后可修改编辑
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;