试题七(共 15 分)阅读下列说明、图和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]已知对某载客车辆(Car)进行类建模,如图 7-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。[Java 代码]class Body{ //此处代码省略 }; //车身类class Passenger{ //此处代码省略 }; //乘客类class Wheel{ //此处代码省略 }; //车轮类class Driver{ //司机类public String name; //表示第几路公交车司机public Driver(String driverName){name = driverName;} //构造函数};class Engine{ //引擎类public String engineNo; //引擎编号public Engine(String engineNo){ this.engineNo = engineNo; } //构造函数};public class Car{ //汽车类static final int (1) = 7; //定义最多载客数static final int MAX_WHEELS = 5; //定义最多轮胎数protected Engine engine;protected Driver driver;protected Body body = new Body();protected Wheel[] wheels;protected Passenger[] passengers;public Car(Driver driver){ //构造函数(2) .driver = driver;engine = new Engine("TX6536 型号引擎");wheels = new Wheel[MAX_WHEELS];passengers = new Passenger[MAX_PASSENGERS];for (int index = 0; index MAX_WHEELS; index++){wheels[index] = new Wheel();}for (int index = 0; index MAX_PASSENGERS; index++){passengers[index] = null;}}int getPassengerNumber(){ //获取车上乘客数量//此处代码省略}void getOnPassenger(Passenger aPassenger ){ //乘客上车//此处代码省略}void run(){ //开车if( (3) ){ System.out.println("司机尚未上车!"); return;}//此处代码省略}public static void main(String args[]){Driver driver = new Driver("第五路公交车司机");Car car = new Car( (4) );for (int index = 0 ; index MAX_PASSENGERS; index ++)car.getOnPassenger( (5) Passenger());car.run();}}
试题七(共 15 分)
阅读下列说明、图和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
[说明]
已知对某载客车辆(Car)进行类建模,如图 7-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。
[Java 代码]
class Body{ //此处代码省略 }; //车身类
class Passenger{ //此处代码省略 }; //乘客类
class Wheel{ //此处代码省略 }; //车轮类
class Driver{ //司机类
public String name; //表示第几路公交车司机
public Driver(String driverName){name = driverName;} //构造函数
};
class Engine{ //引擎类
public String engineNo; //引擎编号
public Engine(String engineNo){ this.engineNo = engineNo; } //构造函数
};
public class Car{ //汽车类
static final int (1) = 7; //定义最多载客数
static final int MAX_WHEELS = 5; //定义最多轮胎数
protected Engine engine;
protected Driver driver;
protected Body body = new Body();
protected Wheel[] wheels;
protected Passenger[] passengers;
public Car(Driver driver){ //构造函数
(2) .driver = driver;
engine = new Engine("TX6536 型号引擎");
wheels = new Wheel[MAX_WHEELS];
passengers = new Passenger[MAX_PASSENGERS];
for (int index = 0; index < MAX_WHEELS; index++){
wheels[index] = new Wheel();
}
for (int index = 0; index < MAX_PASSENGERS; index++){
passengers[index] = null;
}
}
int getPassengerNumber(){ //获取车上乘客数量
//此处代码省略
}
void getOnPassenger(Passenger aPassenger ){ //乘客上车
//此处代码省略
}
void run(){ //开车
if( (3) ){ System.out.println("司机尚未上车!"); return;}
//此处代码省略
}
public static void main(String args[]){
Driver driver = new Driver("第五路公交车司机");
Car car = new Car( (4) );
for (int index = 0 ; index < MAX_PASSENGERS; index ++)
car.getOnPassenger( (5) Passenger());
car.run();
}
}