




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
實(shí)驗(yàn)五:責(zé)任鏈模式實(shí)驗(yàn)五:責(zé)任鏈模式實(shí)驗(yàn)五:責(zé)任鏈模式實(shí)驗(yàn)五:責(zé)任鏈模式編制僅供參考審核批準(zhǔn)生效日期地址:電話:傳真:郵編:實(shí)驗(yàn)5:責(zé)任鏈模式一、實(shí)驗(yàn)?zāi)康谋緦?shí)驗(yàn)要求學(xué)生掌握責(zé)任鏈模式,要求學(xué)生理解責(zé)任鏈模式中的二種角色并完成類的定義及測(cè)試。二、實(shí)驗(yàn)任務(wù)計(jì)算整數(shù)的階乘。要求在計(jì)算階乘時(shí)綜合考慮計(jì)算速度與內(nèi)存占用多少,使用責(zé)任鏈模式分析有哪些類以及這些類的角色,完成這些類的定義并分別測(cè)試每一種處理情況。答:處理者(Handler)角色:類Handler具體處理者(ConcreteHandler)角色:類UseInt、類UseLong、類UseBigInteger(1)處理者(Handler)publicinterfaceHandler{publicvoidhandleRequest(Stringstr);publicvoidsetNextHandler(Handlerhandler);}(2)具體處理者(ConcreteHandler)publicclassUseIntimplementsHandler{ privateHandlerhandler; privateintresult=1;publicvoidhandleRequest(Stringstr){ try{ intn=(str); inti=1; while(i<=n){ result=result*i; if(result<=0){ "超出我的能力范圍,我計(jì)算不了"); (str); return; } i++; } "的階乘:"+result+"\n"); }catch(NumberFormatExceptionexp){ }}publicvoidsetNextHandler(Handlerhandler){ =handler;}}publicclassUseLongimplementsHandler{privateHandlerhandler;longresult=1;publicvoidhandleRequest(Stringstr){ try{ inti=1; longn=(str); while(i<=n){ result=result*i; if(result<=0){ "超出我的能力范圍,我計(jì)算不了"); (str); return; } i++; } "的階乘:"+result+"\n"); }catch(NumberFormatExceptionexp){ } }publicvoidsetNextHandler(Handlerhandler){ =handler;}}publicclassUseBigIntegerimplementsHandler{ privateHandlerhandler; privateBigIntegerresult=newBigInteger("1");publicvoidhandleRequest(Stringstr){ BigIntegern=newBigInteger(str); BigIntegerONE=newBigInteger("1"); BigIntegeri=ONE; while(n)<=0){ result=(i); i=(ONE); } "的階乘:"+result+"\n");}publicvoidsetNextHandler(Handlerhandler){ =handler;}}(3)測(cè)試類:publicclassTest{privateHandleruseInt,useLong,useBigInteger; publicvoidcreateChain(){ useInt=newUseInt(); useLong=newUseLong(); useBigInteger=newUseBigInteger(); (useLong); (useBigInteger); } publicvoidresponseClient(Stringstr){ "計(jì)算"+str+"的階乘"); (str); } publicstaticvoidmain(String[]args){ Testtest=newTest(); (); ("10"); ("20"); ("32"); }}運(yùn)行截圖如下:采購(gòu)審批往往是分級(jí)進(jìn)行的,其常常根據(jù)采購(gòu)金額的不同由不同層次的主管人員來(lái)審批。例如,主任可以審批5萬(wàn)元以下(不包括5萬(wàn)元)的采購(gòu)單,副董事長(zhǎng)可以審批5萬(wàn)元至10萬(wàn)元(不包括10萬(wàn)元)的采購(gòu)單,董事長(zhǎng)可以審批10萬(wàn)元至50萬(wàn)元(不包括50萬(wàn)元)的采購(gòu)單,50萬(wàn)元及以上的采購(gòu)單就需要開(kāi)董事會(huì)討論決定。使用責(zé)任鏈模式分析有哪些類以及這些類的角色,完成這些類的定義并分別測(cè)試每一種處理情況。答:處理者(Handler)角色:類Handler具體處理者(ConcreteHandler)角色:類、類Vice_president、類President、類Meetting(1)處理者(Handler)publicinterfaceHandler{publicvoidhandleRequest(Stringstr);publicvoidsetNextHandler(Handlerhandler);}(2)具體處理者(ConcreteHandler)publicclassChairManimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ longmoney=(str); if(money<50000){ "主任審批"+money+"元"); }else{ "元"+"超出主任范疇"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}classVice_presidentimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ longmoney=(str); if(money>=50000&&money<100000){ "副董事長(zhǎng)審批"+money+"元"); }else{ "元"+"超出副董事長(zhǎng)范疇"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}classPresidentimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ longmoney=(str); if(money>=100000&&money<500000){ "董事長(zhǎng)審批"+money+"元"); }else{ "元"+"超出董事長(zhǎng)范疇"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}classMeettingimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ BigIntegermoney=newBigInteger(str); if(newBigInteger("500000"))>=0){ "會(huì)議審批"+money+"元"); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}(3)測(cè)試類:publicclassTest{ ChairManchairman; Vice_presidentvice_president; Presidentpresident; Meettingmeetting; publicvoidcreateChine(){ chairman=newChairMan(); vice_president=newVice_president(); president=newPresident(); meetting=newMeetting(); (vice_president); (president); (meetting); } publicvoidsetClientRequest(Stringstr){ "采購(gòu)金額:"+str+"元"); (str); } publicstaticvoidmain(String[]args){ Testtest=newTest(); (); ("6000"); ("60000"); ("110000"); ("6000000"); }}運(yùn)行截圖如下:公司請(qǐng)假審批流程如下:如果請(qǐng)假小于3天只需要項(xiàng)目經(jīng)理批復(fù)就行;如果請(qǐng)假大于等于3天,小于7天需要人事經(jīng)理批復(fù);如果請(qǐng)假大于等于7天,小于15天需要總經(jīng)理批復(fù);如果申請(qǐng)請(qǐng)假大于等于15天,決絕批復(fù)。使用責(zé)任鏈模式分析有哪些類以及這些類的角色,完成這些類的定義并分別測(cè)試每一種處理情況。答:處理者(Handler)角色:類Handler具體處理者(ConcreteHandler)角色:類Project_Manager、類Personel_Manager、類Top_Manager、類Meetting(1)處理者(Handler)publicinterfaceHandler{publicvoidhandleRequest(Stringstr);publicvoidsetNextHandler(Handlerhandler);}(2)具體處理者(ConcreteHandler)publicclassProject_ManagerimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ intday=(str); if(day<3){ "項(xiàng)目經(jīng)理批復(fù)\n"); }else{ "超出項(xiàng)目經(jīng)理職權(quán)"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}publicclassPersonel_ManagerimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ intday=(str); if(day>=3&&day<7){ "人事經(jīng)理批復(fù)\n"); }else{ "超出人事經(jīng)理職權(quán)"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}publicclassTop_ManagerimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ intday=(str); if(day>=7&&day<15){ "總經(jīng)理批復(fù)\n"); }else{ "總經(jīng)理考慮"); (str); } }catch(Exceptione){ } } publicvoidsetNextHandler(Handlerhandler){ =handler; }}publicclassMeettingimplementsHandler{ Handlerhandler; publicvoidrequestHandle(Stringstr){ try{ intday=(str); if(day>=15){
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 學(xué)校車停放管理制度
- 學(xué)生常態(tài)化管理制度
- 孵化器空調(diào)管理制度
- 安全勸導(dǎo)站管理制度
- 安全鎖安全管理制度
- 完善莫高窟管理制度
- 實(shí)體烘焙店管理制度
- 實(shí)驗(yàn)室內(nèi)務(wù)管理制度
- 審計(jì)署內(nèi)審管理制度
- 財(cái)政投資評(píng)審咨詢服務(wù)預(yù)算和結(jié)算評(píng)審項(xiàng)目投標(biāo)文件(技術(shù)方案)
- 手術(shù)室醫(yī)療垃圾的分類
- 教育領(lǐng)域中的信息化技術(shù)討論以小學(xué)數(shù)為例
- 2025廣東佛山市南海區(qū)圖書館擬聘用公益一類事業(yè)編制人員歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025屆廣東省深圳寶安區(qū)四校聯(lián)考中考生物全真模擬試卷含解析
- 高中家長(zhǎng)會(huì) 共筑夢(mèng)想,攜手未來(lái)課件-高二下學(xué)期期末家長(zhǎng)會(huì)
- 《混凝土灌注樁檢測(cè)》課件
- 2023年《計(jì)量經(jīng)濟(jì)學(xué)》期末試卷
- 防范非法金融活動(dòng)
- 《人工智能:AIGC基礎(chǔ)與應(yīng)用》題庫(kù) 項(xiàng)選擇題
- 數(shù)字資產(chǎn)投資策略-洞察分析
評(píng)論
0/150
提交評(píng)論