阅读下列说明和Java代码,回答问题,将解答填入答题纸的对应栏内。 【说明】 某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如下图所示。 【Java代码】 classLight{publicLight(){}publicLight(Stringname){/*代码省略*/}publicvoidon(){/*代码省略*/}//开灯publicvoidoff(){/*代码省略*/}//关灯//其余代码省略}(1){publicvoidexecute();}classLightOnCommandimplementsCommand{//开灯命令Lightlight;publicLightOnCommand(Lightlight){this.light=light;}publicvoidexecute(){(2);}}classLightOffCommandimplementsCommand{//关灯命令Lightlight;publicLightOffCommand(Lightlight){this.light=light;}publicvoidexecute(){(3);}}classRemoteControl{//遥控器Command[]onCommands=newCommand[7];Command[]offCommands=newCommand[7];publicRemoteControl(){/*代码省略*/}publicvoidsetCommand(intslot,CommandonCommand,CommandoffCommand){(4)=onCommand;(5)=offCommand;}publicvoidonButtonWasPushed(intslot){(6);}publicvoidofflButtonWasPushed(intslot){(7);}}classRemoteLoader{publicstaticvoidmain(String[]args){RemoteControlremoteControl=newRemoteControl();LightlivingRoomLight=newLight("LivingRoom");LightkitchenLight=newLight("kitchen");LightOnCommandlivingRoomLightOn=newLightOnCommand(livingRoomLight);LightOffCommandlivingRoomLightOff=newLightOffCommand(livingRoomLight);LightOnCommandkitchenLightOn=newLightOnCommand(kitchenLight);LightOffCommandkitchenLightOff=newLightOffCommand(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()