java復(fù)數(shù)類試驗(yàn)報(bào)告_第1頁(yè)
java復(fù)數(shù)類試驗(yàn)報(bào)告_第2頁(yè)
java復(fù)數(shù)類試驗(yàn)報(bào)告_第3頁(yè)
java復(fù)數(shù)類試驗(yàn)報(bào)告_第4頁(yè)
java復(fù)數(shù)類試驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

天津電子信息職業(yè)技術(shù)學(xué)院集中實(shí)訓(xùn)實(shí)訓(xùn)題目: 計(jì)算器的設(shè)計(jì)與實(shí)現(xiàn)系 另U: 計(jì)算機(jī)與軟件技術(shù)系專 業(yè): 軟件技術(shù)專業(yè)班級(jí):姓名:學(xué)號(hào):指導(dǎo)教師: 柴君設(shè)計(jì)時(shí)間:2019年6月16日至2019年6月23日TOC\o"1-5"\h\z\o"CurrentDocument"實(shí)訓(xùn)項(xiàng)目一:兩個(gè)整數(shù)類的實(shí)現(xiàn) 1實(shí)訓(xùn)項(xiàng)目二:復(fù)數(shù)類的實(shí)現(xiàn) 4實(shí)訓(xùn)項(xiàng)目三:分?jǐn)?shù)類的實(shí)現(xiàn) 7\o"CurrentDocument"實(shí)訓(xùn)項(xiàng)目四:身份證驗(yàn)證的實(shí)現(xiàn) 10實(shí)訓(xùn)項(xiàng)目五:標(biāo)識(shí)符驗(yàn)證的實(shí)現(xiàn) 14實(shí)訓(xùn)項(xiàng)目一:兩個(gè)整數(shù)類的實(shí)現(xiàn)1、兩個(gè)整數(shù)類TwoNum的設(shè)計(jì)圖TwoNum兩個(gè)整數(shù)類-numl,num2:int整數(shù)1,整數(shù)2+TwoNum()無參構(gòu)造方法+TwoNum(intnuml,intnum2)有參構(gòu)造方法+add():int加法(實(shí)例方法)+sub():int減法(實(shí)例方法)+mul():int乘法(實(shí)例方法)+div():int除法(實(shí)例方法)+toString():String轉(zhuǎn)換成字符串+setNum1()\getNum1()+setNum2()\getNum2()2、程序運(yùn)行圖本程序運(yùn)行之后,分別在控制臺(tái)中輸入兩個(gè)整數(shù),查看運(yùn)行結(jié)果(包括有異常處理的運(yùn)行結(jié)果)。①正常運(yùn)行話輸入第一個(gè)整數(shù):35諳輸入第二個(gè)整數(shù):12TOC\o"1-5"\h\z35 + 12 = 4735 - 12 = 2335 * 12 = 42035 / 12 = 2圖1.1正常運(yùn)行效果②帶異常的運(yùn)行諳輸入第一個(gè)整數(shù):12諳輸入第二個(gè)整數(shù):|12+0=1212-0=1212*0=012/0=/byzero圖1.2除數(shù)為0的異常請(qǐng)輸入第一個(gè)整數(shù):15話輸入第二個(gè)整數(shù):m.5java.util■工npLrtMisma~tc;hExc:GptiQrL圖1.3輸入錯(cuò)誤數(shù)據(jù)的異常3、類設(shè)計(jì)源代碼classTwoNum{privateintnuml;privateintnum2;publicTwoNum(){}publicTwoNum(intnuml,intnum2){this.numl=numl;this.num2=num2;}publicvoidsetNum1(intnuml){this.numl=numl;}publicvoidsetNum2(intnum2){this.num2=num2;}publicintgetNuml(){returnnuml;}publicintgetNum2(){returnnum2;}publicintAdd(){returnnuml+num2;}publicstaticintAdd(intnuml,intnum2){returnnewTwoNum(numl,num2).Add();}publicintSub(){returnnuml-num2;publicstaticintSub(intnuml,intnum2){returnnewTwoNum(num1,num2).Sub();}publicintMul(){returnnuml*num2;}publicstaticintMul(intnuml,intnum2){returnnewTwoNum(num1,num2).Mul();}publicintDiv(){if(num2==0){thrownewArithmeticException("除數(shù)攵為0");}else{returnnum1/num2;}}publicstaticintDiv(intnum1,intnum2){returnnewTwoNum(num1,num2).Div();}publicStringtoString(){return"("+num1+","+num2+")";}}實(shí)訓(xùn)項(xiàng)目二:復(fù)數(shù)類的實(shí)現(xiàn)1、復(fù)數(shù)類Complex的設(shè)計(jì)圖Complex類名-real:int //實(shí)部-imag:int //虛部-私有的字段+Complex(intreal,intimag)+Complex()+getReal():int+setReal(intreal):void+getImag():int+setReal(intimag):void+add(Complexother):Complex+sub(Complexother):Complex+mul(Complexother):Complex+toString():String十公有的構(gòu)造函數(shù)getset函數(shù)實(shí)例函數(shù)+*publicclassComplexTest{publicstaticvoidmain(String口args){Complexc1=newComplex(1,2);Complexc2=newComplex(3,4);Complexc3;Complexc4;Complexc5;Complexc6=newComplex();System.out.println(c1);System.out.println(c2);c3=c1.Add(c2);System.out.println(c3);c3=Complex.Add(c1,c2);System.out.println(c3);c4=c1.Sub(c2);System.out.println(c4);c4=Complex.Sub(c1,c2);System.out.println(c4);c5=c1.Mul(c2);System.out.println(c5);4c5=Complex.Mul(c1,c2);System.out.println(c5);System.out.println(c6);2、程序運(yùn)行圖<terminat&d>ComplexT&st[Jav1+213+6i0+017金—2+—Bi7+7工-54-161—1+12i3、類設(shè)計(jì)源代碼publicclassComplex{privateintreal;privateintimag;publicComplex(intreal,intimag){this.real=real;this.imag=imag;)publicComplex(){)publicintgetReal(){returnthis.real;)publicvoidsetReal(intreal){this.real=real;)publicintgetImage(){returnthis.imag;publicComplexAdd(Complexother){returnnewComplex(this.real+other.real,this.imag+other.imag);)publicstaticComplexAdd(Complexa,Complexb){returnnewComplex(a.real+b.real,a.imag+b.imag);)publicComplexSub(Complexother){returnnewComplex(this.real-other.real,this.imag-other.imag);)publicstaticComplexSub(Complexa,Complexb){returnnewComplex(a.real-b.real,a.imag-b.imag);)publicComplexMul(Complexother){returnnewComplex(this.real*other.real-this.imag*other.imag,this.real*other.imag+this.imag*other.imag);)publicstaticComplexMul(Complexa,Complexb){returnnewComplex(a.real*b.real-a.imag*b.imag,a.real*b.imag+a.imag*b.imag);)publicStringtoString(){returnreal+"+" +imag+"i";))

實(shí)訓(xùn)項(xiàng)目三:分?jǐn)?shù)類的實(shí)現(xiàn)1、分?jǐn)?shù)類Fraction的設(shè)計(jì)圖Fraction類名-fz:int //分子-fm:int //分母-私有的字段+Fraction(intfz,intfm)+getFz():int+getFm():int+Add(Fractionother):Fraction+Sub(Fractionother):Fraction+Mul(Fractionother):Fraction+Div(Fractionother):Fraction+toString():String十公有的構(gòu)造函數(shù)get函數(shù)實(shí)例函數(shù)+*/自定義工具函數(shù)要求:1、分?jǐn)?shù)要最簡(jiǎn)2、分?jǐn)?shù)為負(fù)時(shí),分子為負(fù),分母為正3、分?jǐn)?shù)為0時(shí),分子為0,分母為14、分?jǐn)?shù)為1時(shí),分子為1,分母為12、程序運(yùn)行圖,Problems@Javadoc/Declaration且Console茲<terminated>Complex[JavaApplication]C:\ProgramFiles(x86)\Java\jre6\b1725/€3/33/32/93/7-5/46/53、類設(shè)計(jì)源代碼publicclassFraction{privateintfz;privateintfm;publicFraction(intfz,intfm){this.fz=fz/GYS(fz,fm);this.fm=fm/GYS(fz,fm);if(fz==0)this.fm=1;if(fm==0)thrownewArithmeticException分母不能為零");if(this.fm<0&&this.fz>0){this.fz*=-1;this.fm*=-1;))publicintgetFz(){returnthis.fz;)publicintgetFm(){returnthis.fm;)privatestaticintGYS(intb,intc){b=Math.abs(b);c=Math.abs(c);if(b==0||c==0)return1;while(b!=c){if(b>c)b=b-c;elsec=c-b;}returnb;}publicFractionAdd(Fractionother){intFz=this.fz*other.fm+other.fz*this.fm;intFm=this.fm*other.fm;returnnewFraction(Fz,Fm);}publicstaticFractionAdd(Fractiona,Fractionb){intFz=a.fz*b.fm+b.fz*a.fm;intFm=a.fm*b.fm;returnnewFraction(Fz,Fm);}publicFractionSub(Fractionother){intFz=this.fz*other.fm-other.fz*this.fm;intFm=this.fm*other.fm;returnnewFraction(Fz,Fm);)publicstaticFractionSub(Fractiona,Fractionb){intFz=a.fz*b.fm-b.fz*a.fm;intFm=a.fm*b.fm;returnnewFraction(Fz,Fm);)publicFractionMul(Fractionother){returnnewFraction(fz*other.fz,fm*other.fm);)publicstaticFractionMul(Fractiona,Fractionb){returnnewFraction(a.fz*b.fz,a.fm*b.fm);)publicFractionDiv(Fractionother){returnnewFraction(fz*other.fm,fm*other.fz);)publicstaticFractionDiv(Fractiona,Fractionb){returnnewFraction(a.fz*b.fm,a.fm*b.fz);)?OverridepublicStringtoString(){returnfz+"/"+fm;))實(shí)訓(xùn)項(xiàng)目四:身份證驗(yàn)證的實(shí)現(xiàn)1、Id類設(shè)計(jì)圖Id類名-id:String字段+ID(stringid)+IsID():boolean-CheckCityCode():boolean-CheckID():boolean-CheckDate():boolean構(gòu)造函數(shù)2、程序運(yùn)行圖3、Id類設(shè)計(jì)源代碼packagetest;publicclassId{privateStringid;privateStaticString口□codeAndCity={(〃11〃,〃北京〃},(〃12〃,〃天津〃},(〃13〃,〃河北〃},{〃14〃,〃山西〃},{〃15〃,〃內(nèi)蒙古〃},{〃21〃,〃遼寧〃}, {〃22〃,〃吉林〃},{〃23〃,〃黑龍10江〃},{〃31〃〃上?!?,{〃32〃,〃江蘇〃),{〃33〃,〃浙江〃),{〃34〃,〃安徽〃),{〃35〃,〃福建〃),{〃36〃,〃江西"),{〃37〃,〃山東〃),{〃41〃,〃河南〃),{〃42〃,〃湖北〃),{〃43〃,〃湖南〃),{〃44〃,〃廣東〃),{〃45〃,〃「西〃),{〃46〃,〃海南〃),{〃50〃,〃重慶〃),{〃51〃,〃四川〃),{〃52〃,〃貴州〃),{〃53〃,〃云南〃),{〃54〃,〃西藏〃),{〃61〃,〃陜西〃),{〃62〃,〃甘肅〃),{〃63〃,〃青?!?,{〃64〃,〃寧夏〃),{〃65〃,〃新疆〃),{〃71〃,〃臺(tái)灣〃),{〃81〃〃香港〃),{〃82〃,〃澳門〃),{〃91〃,〃國(guó)外〃));publicId(Stringid){this.id=id;)publicbooleanIsID(){//判身份證號(hào)是否合法if(CheckCityCode()){System.out.println(〃身份證城市代碼正確〃);}elseSystem.out.println(〃身份證城市代碼不正確〃);if(CheckID()){System.out.println(〃身份證規(guī)則正確〃);}elseSystem.out.println(〃身份證規(guī)則不正確〃);if(CheckDate()){System.out.println(〃身份證日期正確〃);}elseSystem.out.println(〃身份證日期不正確〃);returnCheckCityCode()&&CheckID()&&CheckDate();)privatebooleanCheckCityCode(){//判城市代碼是否合法for(inti=0;i<codeAndCit.length-1;i++){if(id.substring(0,2).equals(codeAndCit[i][0]))returntrue;)returnfalse;)privatebooleanCheckID(){ //判身份證號(hào)規(guī)則是否合法intsum=0;if(id.length()==18){〃判斷第18位數(shù)字int[]aa=newint[]{0,1,2,3,4,5,6,7,8,9,10);Stringabc=newString(〃10X98765432〃);int[]xxx=newint[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);for(inti=0;i<id.length()-1;i++)11(sum+=(id.charAt⑴-'0')*xxx[i];)intfalg=sum%11;for(inti=0;i<aa.length;i++)(if(falg==aa[i])(//System.out.println(i);if(abc.charAt(i)==id.charAt(17))//String.valueOf(abc.charAt(i)).equals(id.substring(17))(returntrue;)))returnfalse;}elsereturnfalse;)privatebooleanCheckDate(){//判日期是否合法Stringy=id.substring(6,10);intyear=Integer.parseInt(y);//2000Stringm=id.substring(10,12);//08intmonth=Integer.parseInt(m);Stringd=id.substring(12,14);//28intday=Integer.parseInt(d);if(Id.CheckDate(year,month,day)){returntrue;}elsereturnfalse;)//判日期privatestaticbooleanCheckDate(intyear,intmonth,intday){if(month<=12&&day<=31){if(day<DaysOfMonth(year,month)){returntrue;}elsereturnfalse;12}elsereturnfalse;)//判閏年privatestaticbooleanIsLeapYear(intyear){if(year%400==0||(year%4==0&&year%100!=0)){returntrue;}else{returnfalse;))//返回某年某月的天數(shù)privatestaticintDaysOfMonth(intyear,intmonth){intday=0;switch(month){case1:case3:case5:case7:case8:case10:case12:day=31;break;case4:case6:case9:day=30;break;case2:if(IsLeapYear(year)){day=28;break;}elseday=29;break;)returnday;))測(cè)試類:packagetest;importjava.util.Scanner;publicclassTestId{publicstaticvoidmain(String口args){Stringid;ScannerA=newScanner(System.in);System.out.println(〃請(qǐng)輸入您的身份證號(hào):〃);id=A.next();Ida=newId(id);13if(a.IsID()){System.out.println(〃該身份證號(hào)碼合法〃);}elseSystem.out.println(〃該身份證號(hào)碼不合法〃);))14

實(shí)訓(xùn)項(xiàng)目五:標(biāo)識(shí)符驗(yàn)證的實(shí)現(xiàn)1、Identifier類設(shè)計(jì)圖Identifier類名-Keywords:String[]-id:String字段+Identifier():+Identifier(Stringid)+getId():String+setId(Stringvalue):void+IsIdentifier():boolean-IsLetter(charch):boolean-IsDigit(charch):boolean2、程序運(yùn)行圖且Consolea<terminated>test[JavaApplication]C:\ProgramFiles(x96)\Jav輸入二語目標(biāo)識(shí)符:mM$a;fk$_gdadc.合法15<terminated>test[JavaApplication]C:\ProgramFiles輸入E語言篇只符工咫皮后非法<terminated>test[JavaApplication]C:\ProgramFiles(x86]\J輸入W語言就只符:非法3、類設(shè)計(jì)源代碼importpiler.Keywords;importjava.util.Scanner;publicclassIdentifier{privatestaticString[]keywords;privateStringid;static{keywords=newString[]{"int","float","double","char","long","unsigned","signed","if","while","do","for","continue","break","switch","return","else","auto","static","register","extern","case","default","enum","goto","short","sizeof","struct","typedef"

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論