听力原文:As investors were encouraged by the news that the U. S. manufacturing sector expanded in June at its fastest pace since April 2006, the Dow Jones industrial average rose more than 120 points.
(84)
查看答案
When does government become a "consideration of convenience"?
项目经理小许应该如何科学地检查及控制项目的进度执行情况?
阅读下列说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
已知某企业欲开发一家用电器遥控系统,即用户使用一个遥控器即可控制某些家用电器的开与关。遥控器如下图(a)所示。该遥控器共有4今按钮,编号分别是0至3,按钮0和2能够遥控打开电器1和电器2,按钮1和3则能遥控关闭电器1和电器2。由于遥控系统需要支持形式多样的电器,因此,该系统的设计要求具有较高的扩展性。现假设需要控制客厅电视和卧室电灯,对该遥控系统进行设计所得类图如下图(b)所示。
图(b)中,类RomoteController的方法onPrcssButton(int button)表示当遥控器按键按下时调用的方法,参数为按键的编号;command接口中on和off方法分别用于控制电器的开与关;Light中turnLight(int degree)方法用于调整电灯灯光的强弱,参数 degree值为0时表示关灯,值为100时表示开灯并且将灯光亮度调整到最大;TV中 sctChannel(int channel)方法表示设置电视播放的频道,参数channel值为0时表示关闭电视,为1时表示开机并将频道切换为第1频道。
【Java代码】
class Light{ //电灯类
public void trunLight(int degree){//调整灯光亮度,0表示关灯,100表示亮度最大}
};
class TV{//电视机类
public void setChannel(int channel){//0表示关机,1表示开机并切换到1频道}
};
interface Command{//抽象命令类
void on();
void off();
};
class RemoteController{ //遥控器类
protected Command []commands=new Command[4];
//遥控器有4个按钮,按照编号分别对应4个Command对象
public void onPressButton(int button){
//按钮被按下时执行命令对象中的命令
if(button % 2 == 0)commands[button]. on();
else commands[button]. off();
}
public void setCommand(int button, Command command){
(1)=command;//设置每个按钮对应的命令对象
}
};
class LightCommand implements Command{ //电灯命令类
protected Light light; //指向要控制的电灯对象
public void on(){light. trunLight(100););
public void off(){light.(2););
public LightCommand(Light light){this. light= light;);
};
class TVCommand implements Command{//电视机命令类
protected Tv tv; //指向要控制的电视机对象
public void on(){tv.(3);};
public void off(){tv. setChanne1(0);};
public TVCommand(TV tv){this. tv= tv;};
};
public class rs {
public static void main(String [] args){
Light light= new Light(); TV tv=new TV();//创建电灯和电视对象
LightCommand lightCommand= new LightCommand(light);
TVCommand tvCommand=new TVCommand(tv);
RemoteController remoteController=new RemoteController();
//设置按钮和命令对象
remoteController. setCommand(0,(4));
... //此处省略设置按钮1、按钮2和按钮3的命令对象代码
}
}
本题中,应用命令模式能够有效让类(5)和类(6)、类(7)之间的耦合性降至最小。