阅读以下说明以及Java程序。【说明】传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening (正在打开)、StayOpen(保持打开)和Closing(正在关闭)五种状态。触发状态的转换事件有click、complete和timeout三种。事件与其相应的状态转换如下图所示。下面的Java代码1与Java代码2分别用两种不同的设计思路对传输门进行状态模拟,请填补代码中的空缺。【Java代码1】public class Door {public static final int CLOSED = 1; public static final int PENING = 2;public static final int PEN = 3; public static final int CLOSING = 4;public static final int STAYOPEN = 5; private int state = CLOSED;//定义状态变量,用不同的整数表示不同状态private void setState(int state){ this.state = state;}//设置传输门当前状态public void getState() {//此处代码省略,本方法输出状态字符串,//例如,当前状态为CLOSED时,输出字符串为"CLOSED"}public void click() { //发生click事件时进行状态转换if ((1);) setState(OPENING);else if ((2);) setState{CLOSING);else if ((3);) setState(STAYOPEN);}//发生timeout事件时进行状态转换public void timeout() { if (state == OPEN) setState(CLOSING);}public void complete() {//发生complete事件时进行状态转换if (state == OPENING) setState(OPEN);else if (state == CLOSING) setState(CLOSED);}public static void main(String [] args){Door aDoor = new Door();aDoor.getState();aDoor.click();aDoor.getState();aDoor.complete();aDoor.getState();aDoor.click();aDoor.getState();aDoor.click();aDoor.getState();return;}}【Java代码2】public class Door {public final DoorState CLOSED = new DoorClosed(this);public final DoorState PENING = new DoorOpening(this);public final DoorState PEN = new DoorOpen(this);public final DoorState CLOSING = new DoorClosing(this);public final DoorState STAYOPEN = new DoorStayOpen(this);private DoorState state = CLOSED;//设置传输门当前状态public void setState(DoorState state) { this.state=state;}public void getState(){ //根据当前状态输出对应的状态字符串System.out.println(state.getClass().getName());}public void click(){(4);}//发生click事件时进行状态转换public void timeout(){(5);}//发生timeout事件时进行状态转换public void complete(){(6);)//发生complete事件时进行状态转换public static void main(String[]args){Door aDoor = new Door();aDoor.getState();aDoor.click();aDoor.getState();aDoor.complete();aDoor.getState();aDoor.timeout();aDoor.getState();return;}}public abstract class DoorState { //定义所有状态类的基类protected Door door ;public DoorState(Door doer) { this.door = door;}public void click() {}public void complete() {}

阅读以下说明以及Java程序。

【说明】

传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening (正在打开)、StayOpen(保持打开)和Closing(正在关闭)五种状态。触发状态的转换事件有click、complete和timeout三种。事件与其相应的状态转换如下图所示。

下面的Java代码1与Java代码2分别用两种不同的设计思路对传输门进行状态模拟,请填补代码中的空缺。

【Java代码1】

public class Door {

public static final int CLOSED = 1; public static final int PENING = 2;

public static final int PEN = 3; public static final int CLOSING = 4;

public static final int STAYOPEN = 5; private int state = CLOSED;

//定义状态变量,用不同的整数表示不同状态

private void setState(int state){ this.state = state;}

//设置传输门当前状态

public void getState() {

//此处代码省略,本方法输出状态字符串,

//例如,当前状态为CLOSED时,输出字符串为"CLOSED"

}

public void click() { //发生click事件时进行状态转换

if ((1);) setState(OPENING);

else if ((2);) setState{CLOSING);

else if ((3);) setState(STAYOPEN);

}

//发生timeout事件时进行状态转换

public void timeout() { if (state == OPEN) setState(CLOSING);}

public void complete() {//发生complete事件时进行状态转换

if (state == OPENING) setState(OPEN);

else if (state == CLOSING) setState(CLOSED);

}

public static void main(String [] args){

Door aDoor = new Door();

aDoor.getState();aDoor.click();aDoor.getState();aDoor.complete();

aDoor.getState();aDoor.click();aDoor.getState();aDoor.click();

aDoor.getState();return;

}

}

【Java代码2】

public class Door {

public final DoorState CLOSED = new DoorClosed(this);

public final DoorState PENING = new DoorOpening(this);

public final DoorState PEN = new DoorOpen(this);

public final DoorState CLOSING = new DoorClosing(this);

public final DoorState STAYOPEN = new DoorStayOpen(this);

private DoorState state = CLOSED;

//设置传输门当前状态

public void setState(DoorState state) { this.state=state;}

public void getState(){ //根据当前状态输出对应的状态字符串

System.out.println(state.getClass().getName());

}

public void click(){(4);}//发生click事件时进行状态转换

public void timeout(){(5);}//发生timeout事件时进行状态转换

public void complete(){(6);)//发生complete事件时进行状态转换

public static void main(String[]args){

Door aDoor = new Door();

aDoor.getState();aDoor.click();aDoor.getState();aDoor.complete();

aDoor.getState();aDoor.timeout();aDoor.getState();return;

}

}

public abstract class DoorState { //定义所有状态类的基类

protected Door door ;

public DoorState(Door doer) { this.door = door;}

public void click() {}

public void complete() {}


相关考题:

现场启动差压变送器的顺序是()。 A、关闭平衡门,打开正压室,打开负压室B、打开负压门,关闭平衡门,打开正压门C、同时打开正,负压门,关闭平衡门

请仔细阅读以下关于某传输系统的技术说明、状态转换图及Java程序,根据要求回答问题1~问题2。[说明]传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、 StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout3种。事件与其相应的状态转换如图7-16所示。下面的[Java代码1]与[Java代码2]分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。[Java代码1]请将以上[Java代码1]与[Java代码2]程序段中,(1)~(7)空缺处的语句填写完整。

阅读以下说明和C++代码。【说明】传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening (正在打开)、StayOpen(保持打开)和Closing(正在关闭)五种状态。触发传输门状态转换的事件有click、complete和timeout三种。事件与其相应的状态转换如下图所示。下面的C++代码1与C++代码2分别用两种不同的设计思路对传输门进行状态模拟,请填补代码中的空缺。【C++代码1】const int CLOSED=1; const int PENING=2;const int PEN=3; const int CLOSING=4;const int STAYOPEN=5; //定义状态变量,用不同整数表示不同状态class Door {Private:int state; //传输门当前状态void setState(int state){ this->state=state;} //设置当前状态public:Door():state(CLOSED){};void getState(){ //根据当前状态输出相应的字符串switch(state){case OPENING: cout<<"OPENING"<<endl; break;case CLOSED: cout<<"CLOSED"<<endl; break;case OPEN: cout<<"OPEN"<<endl; break;case CLOSING: cout<<"CLOSING"<<endl; break;case STAYOPEN:cout<<"STAYOPEN"<<endl; break;}};void click() { //发生click事件时进行状态转换if ((1)) setState(OPENING);else if ((2)) setState(CLOSING);else if ((3)) setState(STAYOPEN);}void timeout(){ //发生timeout事件时进行状态转换if (state == OPEN) setState(CLOSING);}void complete(){ //发生complete事件时进行状态转换if (state == OPENING) setState(OPEN);else if (state == CLOSING) setState(CLOSED);}};int main(){Door aDoor;aDoor.getState();aDoor.click(); aDoor.getState();aDoor.complete();aDoor.getState(); aDoor.click();aDoor.getState();aDoor.click(); aDoor.getState(); return 0;}【C++代码2】class Door {public:DoorState *CLOSED,*OPENING,*OPEN,*CLOSING,*STAYOPEN,*state;Door();virtual~Door(){……//释放申请的内存,此处代码省略);void setState(DoorState *state) { this->state = state;}void getState(){//此处代码省略,本方法输出状态字符串,//例如,当前状态为CLOSED时,输出字符串为“CLOSED”};void click();void timeout();void complete();};Door::Door(){CLOSED = new DoorClosed(this); OPENING = new DoorOpening(this);PEN = new DoorOpen(this); CLOSING = new DoorClosing(this);STAYOPEN = new DoorStayOpen(this);state = CLOSED;}void Door :: click() {(4);)void Door :: timeout() {(5);)void Door :: complete() {(6);}class DoorState//定义一个抽象的状态,它是所有状态类的基类{protected:Door *door;public:DoorState(Door *door) {this->door = door;}virtual~DoorState(void);virtual void click() {}virtual void complete(

请认真阅读以下关于某传输系统的技术说明、状态转换图及C++代码,根据要求回答问题1~问题2。[说明]传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、 StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout3种。事件与其相应的状态转换如图7-15所示。下面的[C++代码1]与[C++代码2]分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。[C++代码1]请将以上[C++代码1]与[C++代码2]程序段中的(1)~(7)空缺处的语句填写完整。

当乘客在电梯门的关闭过程中被门撞击或可能被撞击时,保护装置将停止关门动作并使门()。A.保持静止状态B.重新自动开启C.人为控制打开D.延时关闭

当乘客在电梯门的关闭过程中被门撞击或可能被撞击时,保护装置将停止关门动作并使门______。A.保持静止状态B.重新自动开启C.人为控制打开D.延时关闭

电梯防止夹伤乘客的光电装置动作时,正在关闭的门会马上打开。此题为判断题(对,错)。

请认真阅读以下关于某传输系统的技术说明、状态转换图及C++代码,根据要求回答问题1和问题2。【说明】传输门是传输系统中的重要装置。传输门具有Open(打开)、Closed(关闭)、Opening(正在打开)、StayOpen(保持打开)和Closing(正在关闭)5种状态。触发状态的转换事件有click、complete和timeout 3种,事件与其相应的状态转换如图6-18所示。下面的【C++代码1】与【C++代码2】分别用两种不同的设计思路对传输门进行状态模拟,请填补代码段中的空缺语句。【C++代码1】const int CLOSED = 1; const int PENING = 2;const int PEN = 3; const int CLOSING = 4;const int STAYOPEN = 5; //定义状态变量,用不同整数表示不同状态class Door {private:private:int state; //传输门当前状态void setState(int state) { this->state = stale; } //设置当前状态public:Door () :state (CLOSED) { };void getState() { //根据当前状态输出相应的字符串switch(state) {case OPENING: cout <<"OPENING" << endl; break;case CLOSED: cout << "CLOSED" << endl; break;case OPEN: cout << "OPEN" << endl; break;case CLOSING: cout << "CLOSING" << endl; break;case STAYOPEN: cout << "STAYOPEN" << endl; break;}}void click() { //发生click事件时进行状态转换if ( (1) ) setState(OPENING);else if ( (2) ) setState(CLOSING);else if ( (3) ) setState(STAYOPEN);}void timeout() { //发生timeout事件时进行状态转换if (state == OPEN) setState(CLOSING);}void complete() { //发生complete事件时进行状态转换if (state == OPENING) setState(OPEN);else if (state == CLOSING) setState(CLOSED);}};int main(){Door aDoor;aDoor.getState(); aDoor.click(); aDoor.getState(); aDoor.complete();aDoor.getState(); aDoor.click(); aDoor.getState(); aDoor.click();aDoor.getState(); return 0;}【C++代码2】class Door {public:DoorState *CLOSED, *OPENING, *OPEN, *CLOSING, *STAYOPEN, *state;Door();virtual ~Door() { ... //释放申请的内存,此处代码省略};void s

现场启动差压变送器的顺序()。A关闭平衡门,打开正压门,打开负压门B打开负压门,关闭平衡门,打开正压门C同时打开正负压门。关闭平衡门D打开正压门,打开负压门,关闭平衡门