資源描述:
《云大java實(shí)驗(yàn)5lab5(陸歌浩)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、云南大學(xué)軟件學(xué)院實(shí)驗(yàn)報(bào)告課程:Java程序設(shè)計(jì)實(shí)驗(yàn)學(xué)期:2012-2013學(xué)年第一學(xué)期任課教師:陸歌浩專業(yè):軟件工程學(xué)號(hào):序號(hào):姓名:成績(jī):實(shí)驗(yàn)5Applying00ConceptsUsingJava一、實(shí)驗(yàn)?zāi)康木毩?xí)Java屮而14對(duì)象概念的應(yīng)用一-學(xué)會(huì)使用現(xiàn)有對(duì)象和自定義類。二、實(shí)驗(yàn)內(nèi)容ProgramCreateaclasscalledCircle,javawithfieldsnamedradius,area,anddiameter.IncludemethodsnamedsetRadius(),getRadius,andcomputeDiameter0,whichcal
2、culatesthecircle’sdiameter,andcomputeAreaO,whichcomputesthecircle’sarea.Hint:diameterofacircleistwiceitsradius.Hint:areaofacircleis3.14multipliedbythesquareoftheradius.CreateaclasscalledTestCircle.javawhosemainmethoddeclares2Circleobjects.UsingsetRadius()method,assignoneCircleasmallradius
3、valueandassignanotheralargerradiusvalue.CallcomputeDiameter()andcomputeAreaforeachcircleanddisplaytheresults.Outputresultofusingcommandinput"58":Theareaofais78.5Thediameterofais10.0Theareaofbis200.96Thediameterofbis16.0實(shí)驗(yàn)代碼:importjavax.swing.DOptionPane;publicclassTestCircle{publicstaticv
4、oidmain(String[]args){Circlea=newCircle();Circleb=newCircle();doublerada.radb:rad_a=Double.parseZ?cH/bLe(]OptionPane.showInpwt/?ialog("請(qǐng)輸入圓a的半徑:"));//接收?qǐng)Aa的半徑rad_b=Double.par'seZ?owbLe(]OptionPane.s/?owInpwtDiGLog("請(qǐng)輸入圓b的半徑:"));//接收?qǐng)Ab的半徑a.setRadius(rad_a);//設(shè)置圓a的半徑b.setRadius(rad_b);//設(shè)置圓b
5、的半徑Stringstrl=HTheareaofais11;Stringstr2=HThediameterofais’?;Stringstr3="TheareaofbisStringstr4=HThediameterofbisstr2itJOptionPane.shouMessageDiaLog^null^strl+a.computeArea()+nN++a.computeDiameter()+"u+str3+b.computeArea()+""+str4+b.computeDiameter(),"執(zhí)行結(jié)?果(孫金文一20101120007)〕OptionPa
6、ne?PLAINNESSAGE);}}classCircleprivatedoubleradius;privatedoublearea;privatedoublediameter;staticfinaldoublePI=3.14;publicvoidsetRadius(doublerad)//設(shè)詈.半徑的方法{radius=rad;}publicdoublegetRadius()//返回半徑:的方法{returnradius;}publicdoublecomputeDiameter()//計(jì)算S徑的方法{diameter=radius*2;returndiameter;}
7、publicdoublecomputeArea()//計(jì)算面積的方法{area=PI*Math.pow(radius,2);returnarea;}運(yùn)行截圖:瑜入請(qǐng)輸八園a的半輕確定取消確定敗消執(zhí)行結(jié)果(孫金文——20101120007〕~IjjtfSMfTheareaofais78.5Thediameterofais10.0Theareaofbis200.96Thediameterofbis16.06角定