資源描述:
《云南大學軟件學院Java實驗五》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
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三、實驗內(nèi)容:1、Circle.java2、CircleTest.java3、結(jié)果附加題: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.//默認構(gòu)造方法32.publicMonkey(){33.34.}35.36.//帶參數(shù)構(gòu)造方法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