動(dòng)物特性的面向?qū)ο竺枋鯻第1頁(yè)
動(dòng)物特性的面向?qū)ο竺枋鯻第2頁(yè)
動(dòng)物特性的面向?qū)ο竺枋鯻第3頁(yè)
動(dòng)物特性的面向?qū)ο竺枋鯻第4頁(yè)
動(dòng)物特性的面向?qū)ο竺枋鯻第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、accp v4.0動(dòng)物特性的面向?qū)ο竺枋?accp v4.02 問題描述q 動(dòng)物特性描述q 狗生活在陸地上(是一種陸生動(dòng)物),既是哺乳類的也是肉食性的。狗通常的時(shí)候和人打招呼會(huì)通過“搖搖尾巴”,在被撫摸感到舒服的時(shí)候,會(huì)“旺旺叫”,而在受到驚嚇情緒煩躁時(shí),會(huì)發(fā)出“嗚嗚”聲;q 貓也生活在陸地上(是一種陸生動(dòng)物),既是哺乳類的也是肉食性的。貓通常的時(shí)候和人打招呼會(huì)發(fā)出“喵”的聲音,在被撫摸情緒很好時(shí),會(huì)發(fā)出“咕嚕咕嚕”聲,而在受到驚嚇時(shí),會(huì)發(fā)出“嘶嘶”聲;q 青蛙是一種兩棲動(dòng)物(既是水生動(dòng)物也是陸生動(dòng)物),既不是哺乳類的也不是肉食性的,屬于卵生。當(dāng)青蛙情緒好的時(shí)候,會(huì)在岸邊“呱呱呱”的唱歌,而在

2、受到驚嚇時(shí),會(huì)“撲通一聲跳入水中”; accp v4.03問題分析q首先需要抽取問題描述中對(duì)象q分析每個(gè)對(duì)象所具有的特征q分析每個(gè)對(duì)象所發(fā)出的動(dòng)作q從這些對(duì)象的特征中,抽取類的屬性和方法q分析類之間的關(guān)系,畫出類結(jié)構(gòu)圖accp v4.04難點(diǎn)分析-1抽象類和對(duì)象的基本方法:q 抽取對(duì)象的基本的方法:找出句子中所使用的名詞 例如:在句子“小貓喵喵叫”中,我們能夠確定一個(gè)對(duì)象:貓;q 確定對(duì)象發(fā)出的行為動(dòng)作的基本的方法:找出句子中的動(dòng)詞 例如:“旺旺叫”、“喵喵叫”都屬于對(duì)象發(fā)出的動(dòng)作;q 確定對(duì)象的屬性或者特征的基本的方法:找出句子中的形容詞 例如:“哺乳性的”“肉食性的”“卵生的”等等;q “

3、是”的關(guān)系一般抽象為繼承 例如:狗是一種動(dòng)物,意味著:“狗”類 繼承自“動(dòng)物”類;q “有”的關(guān)系一般抽象為類的屬性 例如:動(dòng)物都有情緒,意味著:“情緒”是“動(dòng)物”類的一個(gè)屬性;accp v4.05難點(diǎn)分析-2 dog:int numberoflegsdog( )sayhello( )sayhello(int newvalue)getnumberoflegs( )cat:int numberoflegscat( )sayhello( )sayhello(int newvalue)getnumberoflegs( )frog:int numberoflegsfrog( )sayhello( )s

4、ayhello(int newvalue)getnumberoflegs( )hasgills( )layseggs( )wateranimal:hasgills( )layseggs( )landanimal:getnumberoflegs( )animal:boolean mammalboolean carnivorousint moodismammal( )iscarnivorous( )setmood(int newvalue)getmood( )sayhello( )sayhello(int moodval)accp v4.06階段劃分q第一階段(60分鐘):不考慮情緒影響動(dòng)物打招

5、呼的方式q第二階段(40分鐘):考慮情緒影響動(dòng)物打招呼 的方式q第三階段(60分鐘):考慮陸生動(dòng)物和水生動(dòng)物accp v4.07第一階段q第一階段(60分鐘):不考慮情緒影響動(dòng)物打招呼的方式q編寫animal類,沒有mood屬性,只有一種sayhello方法;q編寫dog類、cat類和frog類,分別繼承自animal類,實(shí)現(xiàn)與animal類不同的功能;q編寫main方法,分別實(shí)例化以上三個(gè)類的三個(gè)對(duì)象,測(cè)試類方法實(shí)現(xiàn)的正確性;q要求學(xué)員自己動(dòng)手編碼,在編碼的過程中解答學(xué)員提出的問題accp v4.08階段檢查q針對(duì)第一階段抽查學(xué)員的編碼結(jié)果q教員給出點(diǎn)評(píng)accp v4.09第一階段標(biāo)準(zhǔn)代碼演

6、示q第一階段編碼的結(jié)果:abstract class animal protected boolean mammal = true; protected boolean carnivorous = true; public boolean ismammal() return(mammal); public boolean iscarnivorous() return(carnivorous); abstract public string sayhello();abstractabstractprotectedprotectedclass dog extends animal public s

7、tring sayhello() return(搖搖尾巴搖搖尾巴);class cat extends animal public string sayhello() return(喵喵叫喵喵叫);class frog extends animal public frog() mammal = false; carnivorous = false; public string sayhello() return(呱呱呱呱呱呱); extendsextendsextendspublic string sayhello() return(搖搖尾巴);public string sayhello()

8、 return(喵喵叫);public string sayhello() return(呱呱呱); public frog() mammal = false; carnivorous = false; public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog(); if(animal1.ismammal() system.out.println(狗是哺乳動(dòng)物狗是哺乳動(dòng)物); else

9、 system.out.println(狗不是哺乳動(dòng)物狗不是哺乳動(dòng)物); if(animal1.iscarnivorous() system.out.println(狗是肉食動(dòng)物狗是肉食動(dòng)物); else system.out.println(狗不是肉食動(dòng)物狗不是肉食動(dòng)物); system.out.println(狗通常的情況下,和人打招呼的方式為:狗通常的情況下,和人打招呼的方式為: +animal1.sayhello(); dog animal1 = new dog();cat animal2 = new cat();frog animal3 = new frog();animal1.is

10、mammal()animal1.iscarnivorous()animal1.sayhello()accp v4.010第二階段q 第二階段(40分鐘):考慮情緒影響動(dòng)物打招 呼的方式q擴(kuò)充animal類、dog類、cat類和frog類,增加 animal類的mood屬性,并實(shí)現(xiàn)sayhello方法的多態(tài)性;q擴(kuò)充main方法;q 要求學(xué)員自己動(dòng)手編碼,在編碼的過程中解答 學(xué)員提出的問題accp v4.011階段檢查q針對(duì)第二階段抽查學(xué)員的編碼結(jié)果q教員給出點(diǎn)評(píng)accp v4.012第二階段標(biāo)準(zhǔn)代碼演示q第二階段的編碼結(jié)果:abstract class animal public static

11、 final int scared = 1;/情緒不好,煩躁 public static final int comforted = 2;/情緒好 protected boolean mammal = false; protected boolean carnivorous = false; protected int mood = comforted;/情緒屬性 public boolean ismammal() return(mammal); public boolean iscarnivorous() return(carnivorous); abstract public string

12、 sayhello(); abstract public string sayhello(int moodval); public void setmood(int newvalue) mood = newvalue; public int getmood() return(mood); public static final int scared = 1;/情緒好public static final int comforted = 2;/情緒不好,煩躁protected int mood = comforted;/情緒屬性public void setmood(int newvalue)

13、mood = newvalue; public int getmood() return(mood); abstract public string sayhello();abstract public string sayhello(int moodval);class dog extends animal public string sayhello() return(搖搖尾巴); public string sayhello(int moodval) this.setmood(moodval); switch (mood) case scared: return(嗚嗚叫); case c

14、omforted: return(旺旺旺叫); return(搖搖尾巴); class cat extends animal public string sayhello(int moodval) class frog extends animal public string sayhello(int moodval) public string sayhello(int moodval) this.setmood(moodval); switch (mood) case scared: return(嗚嗚叫); case comforted: return(旺旺旺叫); return(搖搖尾

15、巴); public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog(); system.out.println(狗通常的情況下,和人打招呼的方式為: +animal1.sayhello(); system.out.println(狗被撫摸情緒好的時(shí)候,打招呼的方式是: +animal1.sayhello(animal.comforted); system.out.println(狗煩躁的

16、時(shí)候,會(huì): +animal1.sayhello(animal.scared); system.out.println(狗通常的情況下,和人打招呼的方式為: + animal1.sayhello();system.out.println(狗被撫摸情緒好的時(shí)候,打招呼的方式是: + animal1.sayhello(animal.comforted);system.out.println(狗煩躁的時(shí)候,會(huì): + animal1.sayhello(animal.scared);accp v4.013第三階段q第三階段(60分鐘):考慮陸生動(dòng)物和水生動(dòng)物q定義landanimal接口和waterani

17、mal接口;q擴(kuò)充dog類、cat類和frog類,使其實(shí)現(xiàn)相應(yīng)的接口;q擴(kuò)充main方法;q要求學(xué)員自己動(dòng)手編碼,在編碼的過程中解答學(xué)員提出的問題accp v4.014階段檢查q 針對(duì)第二階段抽查學(xué)員的編碼結(jié)果q 抽查學(xué)員編寫的完整代碼,要求學(xué)員上臺(tái)講解, 并演示運(yùn)行結(jié)果q 教員給出點(diǎn)評(píng)accp v4.015第三階段標(biāo)準(zhǔn)代碼演示q 第三階段的編碼結(jié)果:interface landanimal /陸生動(dòng)物接口 public int getnumberoflegs(); /返回有多少只腳interface wateranimal /水生動(dòng)物接口 public boolean getgillflag

18、(); /返回是否有腮 public boolean getlayseggs(); /返回是否產(chǎn)卵interfaceinterfaceclass dog extends animal implements landanimal private int numberoflegs = 4; public int getnumberoflegs() return(numberoflegs); / 實(shí)現(xiàn) landanimal接口class frog extends animal implements landanimal, wateranimal private boolean gillflag =

19、true; private boolean layseggs = true; private int numberoflegs = 4; private boolean tailflag = true; / 實(shí)現(xiàn) wateranimal接口 public boolean getgillflag() return(gillflag); public boolean getlayseggs() return(layseggs); / 實(shí)現(xiàn) landanimal接口 public int getnumberoflegs() return(numberoflegs); implements landa

20、nimalimplements landanimal, wateranimalprivate boolean gillflag = true;private boolean layseggs = true;private int numberoflegs = 4;private boolean tailflag = true;/ 實(shí)現(xiàn) wateranimal接口public boolean getgillflag() return(gillflag); public boolean getlayseggs() return(layseggs); / 實(shí)現(xiàn) landanimal接口 public int getnumberoflegs() return(numberoflegs); public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog()

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝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)論