阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。
[说明]
某应急交通控制系统(TraficControlSystem)在红灯时控制各类车辆(Vehicle)的通行,其类图如下图所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。
类图
下面的Java代码实现以上设计,请完善其中的空缺。
[Java代码]
abstract class Vehicle{
public Vehicle(){ }
abstract void run();
};
interface Emergency{
______;
______;
};
class Car extends Vehicle{
public Car(){ }
void run(){ /*代码略*/ }
};
Class Truck extends Vehicle{
public Truck(){ }
void run() { /*代码略*/ }
};
class PoliceCar ______ {
boolean isEmergency= false;
public PoliceCar(){ }
public PoliceCar(boolean b) {this.isEmergency=b; }
public boolean isEmergent(){ return ______ }
public void runRedLight(){ /*代码略*/ }
};
/*类Ambulance、FireEngine实现代码略*/
public class TraficControlsystem { /*交通控制类*/
private Vehicle[]V=new Vehicle[24];
int numVehicles;
public void control(){
for {int i=0; i<numVehicles; i++){
if(V[i]instanceof Emergency&&((Emergency)v[i]).
isEmergent()){
(______).runRedLight();
}else
______. run();
}
}
void add(Vehicle vehicle){ v[numVehicles++]=vehicle;}/*添加车辆*/
void shutDown(){/*代码略*/}
public static void main(String[]args){
TraficC0ntrolSystem tcs=new TraficControlSystem();
tcs.add(new Car());
tcs.add(new PoliceCar());
tcs.add(new Ambulance());
tcs.add(new Ambulance(true));
tcs.add(new FireEngine(true));
tcs.add(new Truck());
tcs.add(new FireEngine());
tcs.control();
tcs.shutDown();
}
}


