欢迎来到天天文库
浏览记录
ID:38733192
大小:154.00 KB
页数:5页
时间:2019-06-18
《云南大学软件学院Java实验五》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、云南大学软件学院实验报告姓名:定欢学号:20141120188班级:日期:2016年10月20日成绩:JAVA实验五一、实验目的:ApplyingOOConceptsUsingJava二、实验要求:CreateaclasscalledCircle.javawithfieldsnamedradius(半径),area(面积),anddiameter(直径). IncludemethodsnamedsetRadius(),getRadius(),andcomputeDiameter(),whichcalculatesthecircle'sdiameter,andcom
2、puteArea(),whichcomputesthecircle'sarea. Hint: diameterofacircleistwiceitsradius. Hint: areaofacircleis3.14multipliedbythesquareoftheradius. CreateaclasscalledTestCircle.javawhosemainmethoddeclares2Circleobjects. UsingsetRadius()method,assignoneCircleasmallradiusvalueandassignanothera
3、largerradiusvalue. CallcomputeDiameter()andcomputeAreaforeachcircleanddisplaytheresults.Outputresultofusingcommandinput"58":Theareaofais78.5Thediameterofais10.0Theareaofbis200.96Thediameterofbis16.0三、实验内容:1、Circle.java2、CircleTest.java3、结果附加题:1.Monkey.java1.importjava.util.Random;1.im
4、portjava.util.Scanner;2.3.classMonkey{4.privateStringname;5.privatedoubleweight;6.privateintage;7.privatestaticStringhab="吃香蕉";8.publicvoidsetName(Stringname){9.this.name=name;10.}11.12.publicvoidsetWeight(doubleweight){13.this.weight=weight;14.}15.16.publicvoidsetAge(intage){17.this.
5、age=age;18.}19.20.publicStringgetName(){21.returnname;22.}23.24.publicdoublegetWeight(){25.returnweight;26.}27.28.publicintgetAge(){29.returnage;30.}31.//默认构造方法32.publicMonkey(){33.34.}35.36.//带参数构造方法37.publicMonkey(Stringname,doubleweight,intage){38.this.name=name;39.this.weight=weig
6、ht;40.this.age=age;41.}42.43.publicvoidclimbTree(){44.Randomr=newRandom();45.inthigh=r.nextInt(60)+40;46.intbanana=r.nextInt(54);47.System.out.println(name+"会爬树"+"能爬"+high);48.49.if(high>=60){1.System.out.println(name+"会爬树,"+"能爬"+high+","+"摘到"+banana+"香蕉");2.System.out.println("剩下"+(B
7、ananaTree.BanaSum-banana)+"香蕉");3.}4.5.else6.System.out.println("不能摘到香蕉");7.8.}9.10.}2.BananaTree:publicclassBananaTree{doubletreeHigh;staticdoubleBanaSum;publicvoidsettreeHigh(doubletreeHigh){this.treeHigh=treeHigh;}publicvoidsetBanaSum(doubleBanaSum){this.BanaSum=BanaSum;}publicdoub
8、letre
此文档下载收益归作者所有