某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如图6-1所示。
【Java代码】
class Light{
public Light( ){}
public Light(String name){/*代码省略*/}
public void on( ){/*代码省略*/}//开灯
public void off( ){/*代码省略*/}//关灯
//其余代码省略
}
(1){
public void execute( );
}
class LightOnCommand implements Command{//开灯命令
Light light;
public LightOnCommand(Light light){this.light=light;}
public void execute( ){(2);}
}
class LightOffCommand implements Command{//关灯命令
Light light;
public LightOffCommand(Light light){this.light=light;}
public void execute( ){(3);}
}
class RemoteControl{//遥控器
Command[]onCommands=new Command[7];
Command[]offCommands=new Command[7];
public RemoteControl( ){/*代码省略*/}
public void setCommand(int slot,Command onCommand,Command offCommand){
(4)=onCommand;
(5)=offCommand;
}
public void onButtonWasPushed(int slot){
(6);
}
public void offlButtonWasPushed(int slot){
(7);
}
}
class RemoteLoader{
public static void main(String[]args){
RemoteControl remoteControl=new RemoteControl( );
Light livingRoomLight=new Light("Living Room");
Light kitchenLight=new Light("kitchen");
LightOnCommand livingRoomLightOn=new LightOnCommand(livingRoomLight);
LightOffCommand livingRoomLightOff=new LightOffCommand(livingRoomLight);
LightOnCommand kitchenLightOn=new LightOnCommand(kitchenLight);
LightOffCommand kitchenLightOff=new LightOffCommand(kitchenLight);
remoteControl.setCommand(0,livingRoomLightOn,livingRoomLightOff);
remoteControl.setCommand(1,kitchenLightOn,kitchenLightOff);
remoteControl.onButtonWasPushed(0);
remoteControl.offButtonWasPushed(0);
remoteControl.onButtonWasPushed(1);
remoteControl.offButtonWasPushed(1);
}
}
(1)interface Command
(2)light.on()
(3)light.off()
(4)onCommands[slot]
(5)offCommands[slot]
(6)onCommands[slot].execute()
(7)offCommands[slot].execute()
本题考察设计模式的实现,难度较小。根据类图和已有代码可写出空缺的代码.
(1)是Command接口的实现,应该填写interface Command;
(2)和(3)定义了开灯、关灯action,因此,分别填写(2)light->on()(3)light->off();
(4)(5)分别设置“开灯”命令对象、“关灯”命令对象,因此分别填写(4)onCommands[slot](5)offCommands[slot];
(6)(7)分别完成对开灯、关灯命令对象的execute方法的调用,因此分别填写(6)onCommands[slot].execute()
(7)offCommands[slot].execute()。
一台主机的IP地址为202.123.25.36,掩码为255.255.254.0。如果该主机需要在该网络进行直接广播,那么它应该使用的目的地址为( )
在计算机系统的日常维护工作中,应当注意硬盘工作时不能__(2)__。另外,需要防范病毒,而__(3)__是不会被病毒感觉的。
有 4 个 IP 地址:201.117.15.254、201.117.17.01、201.117.24.5 和 201.117.29.3,如果子网掩码为 255.255.248.0,则这 4 个地址分别属于3个子网;其中属于同一个子网的是()
在异步通信中,每个字符包含1位起始位、7位数据位、1位奇偶位和1位终止位,每秒钟传送200个字符,采用4相位调制,则码元速率为()。
在 Windows 中,运行( )命令得到下图所示结果。以下关于该结果的叙述中,错误的是( )。
Pinging 59.74.111.8 with 32 bytes of data:
Reply from 59.74.111.8: bytes=32 time=3ms TTL=60
Reply from 59.74.111.8: bytes=32 time=5ms TTL=60
Reply from 59.74.111.8: bytes=32 time=3ms TTL=60
Reply from 59.74.111.8: bytes=32 time=5ms TTL=60
Ping statistics for 59.74.111.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 3ms, Maximum = 5ms, Average = 4ms
在ISO OSF/RM参考模型中,七层协议中的__(1)__利用通信子网提供的服务实现两个用户进程之间端到端的通信。在这个模型中,如果A用户需要通过网络向B用户传送数据,则首先将数据送入应用层,在该层给它附加控制信息后送入表示层;在表示层对数据进行必要的变换并加头标后送入会话层;在会话层加头标送入传输层;在传输层将数据分解为__(本题)__后送至网络层;在网络层将数据封装成__(3)__后送至数据链路层;在数据链路层将数据加上头标和尾标封装成__(4)__后发送到物理层;在物理层数据以__(5)__形式发送到物理线路。B用户所在的系统接收到数据后,层层剥去控制信息,把原数据传送给B用户。
在OSI/RM中,解释应用数据语义的协议层是()。
在TCP/IP协议栈中,ARP协议的作用是(),RARP协议的作用是(请作答此空)。
在地址 http://www.dailynews.com.cn/channel/welcome.htm 中,www.dailynews.com.cn 表示( ),welcome.htm 表示(请作答此空)。
在电子表格软件Excel中,假设A1单元格的值为15,若在A2单元格输入“=AND(15<A1,A1<100)”,则A2单元格显示的值为 ()