1700458979
1700458980
return false;
1700458981
1700458982
}
1700458983
1700458984
}
1700458985
1700458986
H2型号的悍马设置isAlarm()的返回值为false,也就是关闭了喇叭功能。场景类代码如代码清单10-12所示。
1700458987
1700458988
代码清单10-12 扩展后的场景类
1700458989
1700458990
public class Client{
1700458991
1700458992
public static void main(String[]args)throws IOException{
1700458993
1700458994
System.out.println(”––-H1型号悍马––—”);
1700458995
1700458996
System.out.println(“H1型号的悍马是否需要喇叭声响?0-不需要1-需要”);
1700458997
1700458998
String type=(new BufferedReader(new InputStreamReader(System.in))).readLine();
1700458999
1700459000
HummerH1Model h1=new HummerH1Model();
1700459001
1700459002
if(type.equals(“0”)){
1700459003
1700459004
h1.setAlarm(false);
1700459005
1700459006
}
1700459007
1700459008
h1.run();
1700459009
1700459010
System.out.println(”\n––-H2型号悍马––—”);
1700459011
1700459012
HummerH2Model h2=new HummerH2Model();
1700459013
1700459014
h2.run();
1700459015
1700459016
}
1700459017
1700459018
}
1700459019
1700459020
运行是需要交互的,首先,要求输入H1型号的悍马是否有声音,如下所示:
1700459021
1700459022
––-H1型号悍马––—
1700459023
1700459024
H1型号的悍马是否需要喇叭声响?0-不需要1-需要
1700459025
1700459026
输入“0”后的运行结果如下所示:
1700459027
1700459028
––-H1型号悍马––—
[
上一页 ]
[ :1.700458979e+09 ]
[
下一页 ]