




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、廣東海洋大學(xué)學(xué)生實(shí)驗(yàn)報(bào)告書(學(xué)生用GDOU-B-11-112表)Java程序設(shè)計(jì)與開發(fā) 實(shí)驗(yàn)名稱實(shí)驗(yàn)四.類的基本編程課程名稱 技術(shù) 學(xué)院(系)數(shù)學(xué)與計(jì)算機(jī)學(xué)院專業(yè)計(jì)算機(jī)科學(xué)與技術(shù)課程號(hào)班級(jí)計(jì)科1141Comp lex Imidl = new Comp lex();學(xué)生姓名鄧超榮實(shí)驗(yàn)日期2016.10.2鐘海樓學(xué)號(hào)201411621110實(shí)驗(yàn)地點(diǎn) 040仃實(shí)驗(yàn)?zāi)康?掌握J(rèn)ava類的基本知識(shí)及應(yīng)用實(shí)驗(yàn)內(nèi)容:定義一個(gè)名為Complex的類實(shí)現(xiàn)復(fù)數(shù)概念及運(yùn)算,它的UML圖如下,先實(shí)現(xiàn)該類的相關(guān)方法,再試編寫主方法來測(cè)試該類這些的方法。Comp lex-rea IP art:double -imag i
2、naryP art:double實(shí)部虛部+Com pl ex()+Co mpl ex(double r,double i)默認(rèn)構(gòu)造方法 帶參數(shù)的構(gòu)造方法+getReal Part():double +setReal Part(double d): void返回實(shí)部設(shè)置實(shí)部+getlmagi nary (): double +setlmag inary (double d):void返回虛部 設(shè)置虛部+compl exAdd(Co mp lex c1, Complex c2): Comp lex+compl exAdd(Co mp lex c1, double c2): Comp lex+co
3、mp lexAdd(Co mp lex c1, Comp lex c2, Complex c3): Comple復(fù)數(shù)對(duì)象與復(fù)數(shù)對(duì)象相加 復(fù)數(shù)對(duì)象與實(shí)數(shù)相加:三個(gè)復(fù)數(shù)相加+co mp lexM inu s(Co mp lex c1, Complex c2) : Comp lex +co mp lexM inu s(Co mp lex c1, double c2) : Comp lex復(fù)數(shù)對(duì)象與復(fù)數(shù)對(duì)象相減 復(fù)數(shù)對(duì)象與實(shí)數(shù)相減+co mp lexMul(Co mplex c1, Comp lex c2) : Complex+co mp lexMul(Co mplex c1, double c2)
4、: Comp lex+co mp lexMul(Co mplex c1, Comp lex c2 Complex c3) : Complex復(fù)數(shù)對(duì)象與復(fù)數(shù)對(duì)象相乘 復(fù)數(shù)對(duì)象與實(shí)數(shù)相乘 三個(gè)復(fù)數(shù)相乘+toStri ng():Stri ng以a+bi的形式顯示復(fù)數(shù)(l+2i)+(2+3i)=3+5i(l+2i)+(-2)=-l+2i (l+2i)+(2+3i)+(4-2i)=7+3i (l+2i)-(2+3i)=-l-li (l+2i)-(-2)=3+2i (l+2i)*(2+3i)=-4+7i (l+2i)*(-2)=-2-4i(l+2i)*(2+3i)*(4-2i)=-2+36i代碼:publ
5、ic class ComplexDemo args ) public static void main(StringComplex c1 =new Com plex(1,2);Comp lex c2 =new Comp lex(2,3);Complex c3 =new Com pl ex(4,-2);double c = -2;Complex sum =new Comp lex();sum = sumcomplexAdd( c1, c2);System. out .println("(1+2i)+(2+3i)=" +sum);sum = sumcomplexAdd( c1,
6、 c);System. out .println("(1+2i)+(-2)=" +sum);sum = sumcomplexAdd( c1, c2 , c3);+sum);System. out .println("(1+2i)+(2+3i)+(4-2i)二"classmid| = mid|.complexMinus( c1, c2);System. out .println( "(1+2i)-(2+3i)="mid| = plexMinus( c1, c);System. out .println( "(1+2i)-(-2
7、)="Comp lex mul = new Comp lex();mul = plexMul( c1, c2);System. out .println("(1+2i)*(2+3i)="mul = plexMul( c1, c);System. out .println( "(1+2i)*(-2)="mul = plexMul( c1, c2 , c3);+mid|);+mul);+mul);System. out .println("(1+2i)*(2+3i)*(4-2i)二"+mul);Comp lex double r
8、ealPartdouble imagi naryPartComp lex()默認(rèn)構(gòu)造函數(shù)Com pl ex( double r, double i ) / 帶參數(shù)的構(gòu)造函數(shù)realPartimagi naryParti ;double getRealPart() / 返回實(shí)部return realPartvoid setRealPart( double d) / 設(shè)置實(shí)部realPartd;double getImaginaryPart() / 返回虛部return imaginaryPartvoid setImaginaryPart( doubled) / 設(shè)置虛部imaginaryPart
9、d;/ 復(fù)數(shù)Complex complexAdd(Complexc1 ,Complex c2) 對(duì)象與復(fù)數(shù)對(duì)象相加Complex sum = new Complex();sum. realPartc1. realPart + c2. realPartsum. imaginaryPartc1. imaginaryPart +c2. imaginaryPart/ 復(fù)數(shù)return sum;Complex complexAdd(Complex c1, double c2) 對(duì)象與實(shí)數(shù)相加Complex sum = new Complex();sum. realPartc1. realPart + c
10、2;sum. imaginaryPartc1. imaginaryPartc2. imaginaryPartreturn sum;Complex complexAdd(Complex c1 ,Complex c2 ,Complex c3) / 三個(gè)復(fù)數(shù)相加Complex sum = new Complex();sum. realPartc1. realPart + c2. realPart +c3. realPartsum. imaginaryPartc1. imaginaryPart +c2. imaginaryPart + c3. imaginaryPart/return sum;Comp
11、lex complexMinus(Complexc1 ,Complex c2) 復(fù)數(shù)對(duì)象與復(fù)數(shù)對(duì)象相減Complex mid = new Complex();mid. realPartc1. realPartc2. realPartmid. imaginaryPartc1. imaginaryPartreturn mid;if (imaginaryPart >0) /Complex complexMinus(Complexc1 , double c2) 復(fù)數(shù)對(duì)象與實(shí)數(shù)相減Complex mid = new Complex();mid. realPartc1. realPartc2;mid
12、. imaginaryPartc1. imaginaryPartreturn mid;Complex complexMul(Complexc1 ,Complex c2) / 復(fù)數(shù)對(duì)象與復(fù)數(shù)對(duì)象相乘Complex mul = new Complex();mul. realPartc1. realPart * c2. realPartc1. imaginaryPart * c2. imaginaryPartmul. imaginaryPart = c1. realPart * c2. imaginaryPart+ c1 . imaginaryPart* c2 . realPartreturn mu
13、l;Complex complexMul(Complex c1, double c2) / 復(fù)數(shù)對(duì)象與實(shí)數(shù)相乘Complex mul = new Complex();mul. realPartc1. realPart * c2;return mul;Complex complexMul(Complexc1 ,Complex c2,Complex c3)/三個(gè)復(fù)數(shù)相乘Comp lex mul = new Comp lex();mul. rea IP artc1. realPart* c2. realPartc1. imaginaryPart* c2. imaginaryPartmul. imag
14、inaryPart= c1. realPart * c2. imaginaryPart+ c1. imaginaryPartc2. real Partdouble r =mul.realPartdouble imul.imagi naryPartmul. rea IP artr * c3. rea IP artc3. imaginaryPartmul. imaginaryPartr * c3. imaginaryPart + i *c3. real Partreturn mul;public Stri ng toStri ng() /以a+bL的形式顯示復(fù)Stri ng s = new Stri ng();if (realPart !=0)s = ( int ) realPart + "+" + ( int ) imaginaryPartH:Helse if ( imaginaryPart =0) s = String. valueOf ( int ) realPar
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 第5課《七律·長(zhǎng)征》教學(xué)設(shè)計(jì)-2024-2025學(xué)年語文六年級(jí)上冊(cè)統(tǒng)編版
- 2025至2031年中國人造花盆景行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025至2030年中國香辣火鍋調(diào)料數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- Module 2 Unit 1 She learnt English.(教學(xué)設(shè)計(jì))-2023-2024學(xué)年外研版(三起)英語五年級(jí)下冊(cè)
- 2025至2030年中國精密四柱龍門式油壓裁斷機(jī)數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025至2030年中國燃煤熔鹽爐數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025至2030年中國摩托車手把前蓋數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 百級(jí)潔凈室裝修施工方案
- 2025至2030年中國壓縮浴巾數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025至2030年中國中藥原料數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 光伏電站小EPC規(guī)定合同范本
- 2024年01月江蘇2024年昆山鹿城村鎮(zhèn)銀行第三期校園招考筆試歷年參考題庫附帶答案詳解
- 中國人口研究專題報(bào)告-中國2025-2100年人口預(yù)測(cè)與政策建議-西南財(cái)經(jīng)大學(xué)x清華大學(xué)-202501
- 建筑工程安全與管理
- 2024年醫(yī)療器械經(jīng)營(yíng)質(zhì)量管理規(guī)范培訓(xùn)課件
- 中華人民共和國學(xué)前教育法-知識(shí)培訓(xùn)
- 2023年新高考(新課標(biāo))全國2卷數(shù)學(xué)試題真題(含答案解析)
- GB/T 19228.1-2024不銹鋼卡壓式管件組件第1部分:卡壓式管件
- 2024年計(jì)算機(jī)二級(jí)WPS考試題庫380題(含答案)
- 人教版六年級(jí)美術(shù)下冊(cè)全冊(cè)課件【完整版】
- 教科版三年級(jí)下冊(cè)科學(xué)全冊(cè)完整課件
評(píng)論
0/150
提交評(píng)論