1700458970
protected void stop(){
1700458971
1700458972
System.out.println(“悍马H2停车……”);
1700458973
1700458974
}
1700458975
1700458976
//默认没有喇叭的
1700458977
1700458978
protected boolean isAlarm(){
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
[
上一页 ]
[ :1.70045897e+09 ]
[
下一页 ]