信管网试题内容
信管网 导航

试卷名称:2023年上半年软件设计师真题(下午案例分析)

考试年份:2023年上半年

试题来源:《2023年上半年软件设计师真题(下午案例分析)》在线考试

试题内容

试题五
阅读下列说明和Java代码,将应填入 (n)处的字写在答题纸的对应栏内
【说明】
在某系统中,类interval代表由下界(lower bound)和上界(upper bound)定义的区间。要求采用不同的格式显示区间范围。如[lower bound.upper bound]:[lower bound...upper bound];[lower bound-upper bound]等现采用策略(strategy)模式实现该要求,得到如图5-1所示的类图。

图5-1类图
[Java代码]
import Java.util
enum TYPE { COMMA, DOTS,LINE }
interface PrintStrategy {
Public(1);
}
class Interval {
private double lowerBound:
private double upperBound:
public Interval(double pLower, double pUpper){
lowerBound = pLower;
upperBound = pUpper:
}
public void printInterval(PrintStrategy ps){
(2);
}
public double getLower(){
return lowerBound;
}
public double getUpper(){
return upperBound;
}
}
class PrintIntervalLine implements PrintStrategy {
public void doPrint(Interval val){
Svstem.out.println("["+ val.getLower()+"-"+val.getUppei
0+"]");
}
}
class PrintIntervalDots implements PrintStrategy {
public void doPrint(Interval val){
System.out.println("["+ val.getLower()+".."+ val.getUppe
r()+"]");
}
}
class PrintIntervalComma implements PrintStrategy {
public void doPrint(Interval val){
System.out.println("["+val.getLower()+","+ val.getUpper
0+"]");
}
}
ublic class Client {
public static PrintStrategy getStrategy(TYPE type){
PrintStrategy st = null;
switch(type){
case COMMA:
(3)
break;
case DOTS:
(4);
break;
case LINE:
(5);
break;
}
return st;
}
public static void main(String[] args){
Interval interval = new Interval(1.7,2.1);
interval printInterval(getStrategy(TYPE.COMMA));
interval printInterval(getStrategy(TYPE.DOTS));
interval printInterval(getStrategy(TYPE.LINE));
}
}
参考答案:暂时没有答案(仅供参考) 收藏

【解析】

普通会员无法查看试题解析。[开通试题解析服务]