


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、中學(xué)學(xué)院實(shí)驗(yàn)專業(yè)工程課程名稱 JAVA 面對對象程序設(shè)計(jì) 1414011529學(xué)號 姓名輔導(dǎo)教師 成績實(shí)驗(yàn)日期2015 年 3 月24 日實(shí)驗(yàn)時間下午19:0021:001 實(shí)驗(yàn)名稱 :實(shí)驗(yàn)四 深入面象程序設(shè)計(jì)(一)2、實(shí)驗(yàn)?zāi)康?、 熟練掌握類的抽象和構(gòu)造方法的定義。2、 掌握對象的組合和對象數(shù)組。3、實(shí)驗(yàn)內(nèi)容編寫 Java 程序,構(gòu)造一個瓶子類(該瓶子由一個長方體和一個球體),計(jì)算瓶子的體積,并編寫主類構(gòu)造幾個瓶子測試該類的功能。4、實(shí)驗(yàn)原理或流程圖5、實(shí)驗(yàn)過程或源代碼 import java.util.*; public class Work4public sic void main(St
2、ring args) float volume;float area;Bottottle=new Bottle();Scanner reader=new Scanner(System.in); i=1;doSystem.out.prln();System.out.prln( 要選擇下列哪條數(shù)據(jù)?); System.out.prln();System.out.prln(1.該瓶子的體積n2.該瓶子的面積); System.out.prln(3.該瓶子的球的體積n4.該瓶子的球的面積);System.out.prln(5.該瓶子的長方體的體積n6.該瓶子的長方體的面積);System.out.pr
3、ln();C1=reader.next();switch(C1)case 1:System.out.prln(該瓶的體積為+bottle.getVolume();break;case 2:System.out.prln(該瓶的面積為+bottle.getArea();break;case 3:System.out.prln(該球的體積為+bottle.getBallVolume();break;case 4:System.out.prln(該球的面積為+bottle.getBallArea();break;case 5:System.out.pr+bottle.getRectVolume();
4、ln(該長方體的體積為break;case 6:System.out.pr+bottle.getRectArea();ln(該長方體的面積為break;default:System.out.prln(輸出錯誤請重新輸入);System.out.prln(請問是否要查詢其他信息?);System.out.prln(是輸入1n 否除1以外任意數(shù)字);i=reader.next();while(i=1);class Ballfloatr;floatvolume;floatarea;public Ball()System.out.prln(請輸入該瓶子的球體的半徑:);Scanner reader=
5、new Scanner(System.in);r = reader.nextFloat();float getVolume()volume=3.0f*(3.14f)/4.0f*r*r*r;return volume;float getArea()area=4.0f*3.14f*r*r;return area;class Rectfloathigh;floatwide;floength;floatvolume;floatarea;public Rect()Scanner reader= newScanner(System.in);System.out.prln(請根據(jù)提示分別輸入瓶子的長方體的屬
6、性);System.out.prf(long:);length = reader.nextFloat();System.out.prf(wighte:);wide = reader.nextFloat();System.out.prf(high:);high = reader.nextFloat();float getVolume()return high*wide*length;float getArea()return high*wide*2+high*length*2+wide*length*2;class Bottlefloat area;float volume;Ball ball
7、= new Ball();Rect rect = new Rect();Bottle()area=ball.getArea()+rect.getArea();volume=ball.getVolume()+rect.getVolume();float getVolume()return volume;float getArea()return area;float getBallVolume()return ball.getVolume();float getBallArea()return ball.getArea();float getRectVolume()return rect.getVolu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 肛瘺護(hù)理課件
- 對口統(tǒng)招數(shù)學(xué)試卷
- 對口本科數(shù)學(xué)試卷
- 東營高考一模數(shù)學(xué)試卷
- 玻璃維修培訓(xùn)課件大全
- 2025至2030磁引導(dǎo)膠囊內(nèi)鏡行業(yè)市場深度研究與戰(zhàn)略咨詢分析報(bào)告
- 2024年汕尾市市直單位招聘政府聘員筆試真題
- 2024年撫順職業(yè)技術(shù)學(xué)院輔導(dǎo)員考試真題
- 2025至2030餐飲行業(yè)市場深度研究及發(fā)展前景投資可行性分析報(bào)告
- 高二基礎(chǔ)數(shù)學(xué)試卷
- 2025年中考語文備考之12部名著閱讀習(xí)題及參考答案
- 1998-2017年中科院植物學(xué)考研真題及答案匯編
- 兒童相機(jī)市場的發(fā)展趨勢分析
- 血液凈化護(hù)理知識競賽考試題庫500題(含答案)
- 帶孩子免責(zé)協(xié)議書范本
- 守護(hù)生命之窗-氣管切開患者護(hù)理
- 信息技術(shù)咨詢服務(wù)合同5篇
- 2022年6月天津市普通高中學(xué)業(yè)水平合格性考試化學(xué)試卷
- 生豬購銷合同協(xié)議
- 蘇教版六年級科學(xué)下冊期末測試卷及答案
- 人教版高中物理(必修一)同步講義+練習(xí)4.6 超重和失重(含解析)
評論
0/150
提交評論