第八次实验报告

第八次实验报告

ID:25547659

大小:167.03 KB

页数:11页

时间:2018-11-20

第八次实验报告_第1页
第八次实验报告_第2页
第八次实验报告_第3页
第八次实验报告_第4页
第八次实验报告_第5页
资源描述:

《第八次实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、第八次实验实验1:中国人、北京人和美国人1.实验要求:编写程序模拟中国人、美国人是人,北京人是中国人。除主类外,程序中还有4个类:People、ChinaPeople、AmericanPeople和BeijingPeople类。要求如下:(1)People类有权限是protected的double型成员变量height和weight,以及publicvoidspeakHello()、publicvoidaverageHeight()和publicvoidaverageWeight()方法。(2)Ch

2、inaPeople类是People的子类,新增了publicvoidaverageHeight()和publicvoidaverageWeight()方法。(3)AmericanPeople类是People的子类,新增方法publicvoidAmericanBoxing()。要求AmericanPeople重写父类的publicvoidspeakHello()、publicvoidaverageHeight()和publicvoidaverageWeight()方法。(4)BeijingPeople

3、类是ChinaPeople的子类,新增publicvoidbeijingOpera()方法。2.实验代码://People.javapublicclassPeople{protecteddoubleweight,height;publicvoidspeakHello(){System.out.println("yayayaya");}publicvoidaverageHeight(){height=173;System.out.println("averageheight:"+height);}pu

4、blicvoidaverageWeight(){weight=70;System.out.println("averageweight:"+weight);}}//ChinaPeople.javapublicclassChinaPeopleextendsPeople{publicvoidspeakHello(){System.out.println("您好");}publicvoidaverageHeight(){height=168.78;System.out.println("中国人的平均身高:

5、"+height+"厘米");}publicvoidaverageWeight(){weight=65;System.out.println("中国人的平均体重:"+weight+"千克");}publicvoidchinaGongfu(){System.out.println("坐如钟,站如松,睡如弓");}}//AmericanPeople.javapublicclassAmericanPeopleextendsPeople{publicvoidspeakHello(){System.out.p

6、rintln("Howdoyoudo");}publicvoidaverageHeight(){height=176;System.out.println("American'saverageheight:"+height+"厘米");}publicvoidaverageWeight(){weight=75;System.out.println("American'saverageweight:"+weight+"kg");}publicvoidamericanBoxing(){System.out

7、.println("直拳,勾拳,组合拳");}}//BeijingPeople.javapublicclassBeijingPeopleextendsChinaPeople{publicvoidaverageHeight(){height=172.5;System.out.println("北京人的平均身高:"+height+"厘米");}publicvoidaverageWeight(){weight=70;System.out.println("北京人得平均体重:"+weight+"千克");}

8、publicvoidbeijingOpera(){System.out.println("花脸、青衣、花旦和老生");}}//Example.javapublicclassExample{publicstaticvoidmain(Stringarg[]){ChinaPeoplechinaPeople=newChinaPeople();AmericanPeopleamericanPeople=newAmericanPeople();BeijingPeoplebeijin

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。