摘要:2023上半年軟件設(shè)計師下午的考試已結(jié)束,希賽小編整理了網(wǎng)友回憶版2023上半年軟件設(shè)計師下午真題答案(四),希望對考生有所幫助。
很多考生關(guān)注2023上半年軟件設(shè)計師下午的真題及答案,希賽小編整理了網(wǎng)友回憶版2023上半年軟件設(shè)計師下午真題答案(四),完整版真題可在本文文首或文末本文資料處下載。答案解析請考生關(guān)注考后公開課。
試題四:
閱讀下列說明和Java代碼,將應(yīng)填入(n)處的字句寫在答題紙的對應(yīng)欄內(nèi)。
[說明]
在某系統(tǒng)中,類interval代表由下界( lower bound )和上界( upper bound )定義的區(qū)間。要求采用不同的格式顯示區(qū)間范圍。如[lower bound.upper bound] ; [lower bound..upper bound] ; [lower bound-upper bound]等現(xiàn)采用策略( strategy )模式實現(xiàn)該要求,得到如圖5- 1所示的類圖。
[Java代碼]
import Java.util.enum;
TYPE {commA,Dots,LINE}
interface printstrategy{
public (1);
(1):void doprint(interval val);
}
class Inrevals{
//兩個類成員變量=上下邊界值
public void Intervals(double lower,double upper){
//初始化上下邊界值
}
Public double getlower {return lover... }
Public double getupper {return lover..}
public void printInterval(PintStrategy pr){
(2);
}
}
class print intervalscomma implements printstrategy{
Public void doprint ( interval Val ) {
system. out.printin("I" +val(.getlowerO+","+val. getupper()
+"I";
}
}
class printIntervalsDots implements Printstrategy{
public void doprint (interval val){
system.out.print(a("I" +val.getlower()+"..."+val(......);
}
}
class PrintIntervalsLine implements PrintStrategy{
public void doprint(interval val){
system.out.print("["+val.getLower()+"-"+val.getUpper()+"]");
}
Public static PrintStrategygetstrategy (TYPE){
type
Print Strategyst=null ,
switch(type) {
case COMMA :
(3) ;
break;
case DoTs:
(4) ;
break;
case LINE:
(5) ;
break;
return st;
}
Public static void main{String[] args} {
Interaala= new Intervals(1.7,2.1);
a.print Interval ( get strategy (TYPE. COMMA));
a.print Interval ( get strategy (TYPE.Dots);
a.print Interval ( get strategy (TYPE.LINE));
}
}
軟考備考資料免費領(lǐng)取
去領(lǐng)取