2006年11月軟件設(shè)計(jì)師下午試題[7]

軟件設(shè)計(jì)師 責(zé)任編輯:yz888520 2008-08-06

添加老師微信

備考咨詢

加我微信

摘要:試題七(共15分)閱讀以下說明以及Java程序,將應(yīng)填入(n)處的字句寫在答題紙的對(duì)應(yīng)欄內(nèi)。[說明]傳輸門是傳輸系統(tǒng)中的重要裝置。傳輸門具有Open(打開)、Closed(關(guān)閉)、Opening(正在打開)、StayOpen(保持打開)、Closing(正在關(guān)閉)五種狀態(tài)。觸發(fā)狀態(tài)的轉(zhuǎn)換事件有click、complete和timeout三種。事件與其相應(yīng)的狀態(tài)轉(zhuǎn)換如圖7-1所示。

試題七(共15分)
閱讀以下說明以及Java程序,將應(yīng)填入 (n) 處的字句寫在答題紙的對(duì)應(yīng)欄內(nèi)。
[說明]
傳輸門是傳輸系統(tǒng)中的重要裝置。傳輸門具有Open(打開)、Closed(關(guān)閉)、Opening(正在打開)、StayOpen(保持打開)、Closing(正在關(guān)閉)五種狀態(tài)。觸發(fā)狀態(tài)的轉(zhuǎn)換事件有click、 complete和timeout三種。事件與其相應(yīng)的狀態(tài)轉(zhuǎn)換如圖7-1所示。



 下面的[Java代碼1]與[Java代碼2]分別用兩種不同的設(shè)計(jì)思路對(duì)傳輸門進(jìn)行狀態(tài)模擬,請(qǐng)?zhí)钛a(bǔ)代碼中的空缺。
[Java代碼1]
public class Door{
public static final int CLOSED = 1; public static final int OPENING = 2:
public static final int OPEN = 3: public static final int CLOSING = 4:
public static final int STAYOPEN = 5; private int state = CLOSED:
//定義狀態(tài)變量,用不同的整數(shù)表示不同狀態(tài)

private void setState(int state){this.state = state;}//設(shè)置傳輸門當(dāng)前狀態(tài)
public void getState(){
//此處代碼省略,本方法輸出狀態(tài)字符串,
//例如,當(dāng)前狀態(tài)為CLOSED時(shí),輸出字符串為"CLOSED"
}
public void click(){//發(fā)生click事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換
if( (1) )setState(OPENING);
else if( (2) )setState(CLOSING);
else if( (3) )setState(STAYOPEN);
}
//發(fā)生timeout事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換
public void timeout(){if(state == OPEN) setState(CLOSING);}
public void complete(){//發(fā)生complete 事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換
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.clik();
aDoor.getState();return;
}
}
[Java代碼2]
public class Door{
public final DoorState CLOSED = new DoorClosed(this);
public final DoorState OPENING = new DoorOpening(this);
public final DoorState OPEN = new DoorOpen(this);
public final DoorState CLOSING = new DoorClosing(this);
public final DoorState STAYOPEN = new DoorStay0pen(this);
private DoorState state = CLOSED;

//設(shè)置傳輸門當(dāng)前狀態(tài)
public void setState(DoorState state){this.state = state;}
public void getState(){//根據(jù)當(dāng)前狀態(tài)輸出對(duì)應(yīng)的狀態(tài)字符串
System.out?println(state.getClass().getName());
}
public void click(){ (4) ;}//發(fā)生click事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換
public void timeout(){ (5) ;}//發(fā)生timeout事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換
public void complete(){ (6) ;}//發(fā)生complete事件時(shí)進(jìn)行狀態(tài)轉(zhuǎn)換

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{//定義所有狀態(tài)類的基類
protected Door door:
public DoorState(Door door){this.door = door;}
public void click(){}
public void complete(){}
public void timeout(){}
}
class DoorClosed extends DoorState{//定義一個(gè)基本的Closed狀態(tài)
public DoorClosed(Door door){super(door);}
public void click(){ (7) ;}
//該類定義的其余代碼省略
}
//其余代碼省略
 
[答案討論]

[1]  [2]  [3]  [4]  [5]  [6]  [7]  

更多資料
更多課程
更多真題
溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,本網(wǎng)站提供的以上信息僅供參考,如有異議,請(qǐng)考生以權(quán)威部門公布的內(nèi)容為準(zhǔn)!

軟考備考資料免費(fèi)領(lǐng)取

去領(lǐng)取

!
咨詢?cè)诰€老師!