//汽车业务类
public class MotoOperation {
//定义汽车类型的数组,将该数组声明为父类类型
MotoVehicle[] motos=new MotoVehicle[8];
//初始化汽车信息
public void init(){
motos[0]=new Car("京A88888","宝马",800,"X6");//MotoVehicle m=new Car();
motos[1]=new Car("京A88887","宝马",600,"550i");
motos[2]=new Car("京A88886","别克",300,"林荫大道");
motos[3]=new Car("京A88885","别克",600,"GL8");
motos[4]=new Bus("京A88884","金杯",800,16);//MotoVehicle m=new Bus();
motos[5]=new Bus("京A88883","金杯",1500,34);
motos[6]=new Bus("京A88882","金龙",800,16);
motos[7]=new Bus("京A88881","金龙",1500,34);
}
// 租车:根据用户提供的条件去汽车数组中查找相应车辆并返回
// 如果租赁的是客车 需要的条件:品牌 座位数 型号null
// 如果租赁的是轿车 需要的条件:品牌 型号 座位0
public MotoVehicle motoLeastOut(String brand,String type,int seat){
MotoVehicle moto=null;
for(MotoVehicle mymoto:motos){
if(mymoto instanceof Car){
Car car=(Car)mymoto;
if(car.getBrand().equals(brand)&&car.getType().equals(type)){
moto=car;
break;
}
}else{
Bus bus=(Bus)mymoto;
if(bus.getBrand().equals(brand)&&bus.getSeatCount()==seat){
moto=bus;
break;
}
}
}
return moto;
}
}