




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上EXP2課題(項(xiàng)目)名稱: 實(shí)驗(yàn)二 面向?qū)ο蟪绦蛟O(shè)計(jì)計(jì)劃學(xué)時(shí):2 實(shí)驗(yàn)類型: 1.演示性 2.驗(yàn)證性 3.綜合性 4.設(shè)計(jì)性 5.其它授課日期: 年 月 日 第 周 星期 第 節(jié)實(shí)驗(yàn)?zāi)康?. 驗(yàn)證面向?qū)ο笕筇匦?. 學(xué)習(xí)封裝的實(shí)現(xiàn)3. 學(xué)習(xí)繼承的實(shí)現(xiàn)4. 編寫多態(tài)實(shí)例5. 學(xué)習(xí)抽象類的使用6. 學(xué)習(xí)接口的使用實(shí)驗(yàn)要求1. 掌握封裝的實(shí)現(xiàn)方法2. 掌握繼承的編程方式和思想3. 理解多態(tài)現(xiàn)象4. 掌握抽象類和接口的使用實(shí)驗(yàn)內(nèi)容與步驟1. 封裝的實(shí)現(xiàn)(1) 編寫程序模擬個(gè)人銀行賬號(hào)類。考慮個(gè)人銀行的特點(diǎn),建立類模型(注意屬性和方法的訪問權(quán)限修飾符)參考代碼public c
2、lass BankAccount private String accountID;private String password;private int balance;public BankAccount(String accountID,String password,String operator)this.accountID=accountID;this.password=password;this.balance=0;System.out.println("Create a BankAccount");System.out.println("Accou
3、ntID:"+this.accountID);System.out.println("Current Balance:"+this.balance);System.out.println("Operator:"+operator);System.out.println("Save Account info to Database");public void queryBalance(String password)if(password=this.password)System.out.println("Passw
4、ord OK");System.out.println("Current Account Balance:"+this.balance);elseSystem.out.println("Password Erro");public void changePassword(String oldPassword,String newPassword)if(oldPassword=this.password)System.out.println("Password OK");this.password=newPassword;Sy
5、stem.out.println("Change Passord OK");elseSystem.out.println("Password Erro");public void deposit(int money,String operator)this.balance+=money;System.out.println("add balance OK.Operator:"+operator);System.out.println("Save Account change to database");public
6、 void withdraw(String password,int money,String operator)if(password=this.password)System.out.println("Password OK");if(this.balance>money)this.balance-=money;System.out.println("withdraw:"+money+" ok, Operator:"+operator );System.out.println("Current Account Ba
7、lance:"+this.balance);System.out.println("Save Account change to database");elseSystem.out.println("withdraw:"+money+" erro. Because of not enough balance");elseSystem.out.println("Password Erro");(2) 編寫測(cè)試類,完成如下(1)中類方法的測(cè)試實(shí)現(xiàn)如下業(yè)務(wù):開戶,存款100,查詢余額,取款50,查詢余額,取款2
8、00,查詢余額public class Test1 public static void main(String args) BankAccount bankaccount =new BankAccount("", "", "TOM");bankaccount.queryBalance("");bankaccount.changePassword("","");bankaccount.deposit(100,"TOM");bankaccount.withd
9、raw("",50,"TOM");2. 繼承的實(shí)現(xiàn)(1) 按如下類圖編寫代碼 參考代碼class Person String id;String name;String age;public void sleep() System.out.println("I am Person,I am sleeping");public void eat() System.out.println("I am Person,I am eating");class Student extends Person String sno
10、;public void study() System.out.println("I am Student,I am studying");class Teacher extends Person String tid;public void tech() System.out.println("I am Student,I am taching");(2) 編寫測(cè)試類并創(chuàng)建main()方法,完成如下操作A 分別創(chuàng)建Person、Student、Teacher對(duì)象,完成屬性和每個(gè)方法的調(diào)用測(cè)試B 在Student和Teacher中完成eat()方法的重寫
11、C 編寫類型轉(zhuǎn)化示例(向上類型轉(zhuǎn)化、向下類型轉(zhuǎn)化)3. 多態(tài)現(xiàn)象 在完成(2)中Student、Teacher類eat()方法重寫后,在測(cè)試類中編寫如下代碼并在main()方法中調(diào)用static void askAllToEat(Person ps) for(int i=0;i<ps.length;i+) psi.eat(); psi.sleep(); 從以上代碼中體會(huì)多態(tài)現(xiàn)象。public class Test2 public static void main(String args) Person person = new Person();person.sleep();person
12、.eat();Student student = new Student();student.sleep();student.eat();student.study();Teacher teacher = new Teacher();teacher.sleep();teacher.eat();teacher.tech();static void askAllToEat(Person ps) for (int i = 0; i < ps.length; i+) psi.eat();psi.sleep();4. 抽象類的使用編寫以上類圖所示類,并編寫測(cè)試代碼測(cè)試抽象類的使用參考代碼abstr
13、act class Printerprivate String printerType;Printer(String printerType)this.printerType=printerType;abstract void print(String txt);void showMyType()System.out.println("My Type is:"+printerType);class InkPrinter extends PrinterInkPrinter(String inkPrinterType)super(inkPrinterType);void pri
14、nt(String txt)System.out.println("I am Ink Printer");System.out.println("Start to Print:"+txt);class LasertPrinter extends PrinterLasertPrinter(String laserPrinterType)super(laserPrinterType);void print(String txt)System.out.println("I am Lasert Printer");System.out.pri
15、ntln("Start to Print:"+txt);編寫測(cè)試類及main() 方法,完成如下操作A. 創(chuàng)建Printer,InkPrinter,LaserPrinter類的對(duì)象。B. 設(shè)計(jì)并編寫演示多態(tài)現(xiàn)象的代碼5. 接口的使用編寫以上類圖的代碼,并編寫測(cè)試類測(cè)試接口的使用參考代碼interface IScanvoid scan();abstract class Printerprivate String printerType;Printer(String printerType)this.printerType=printerType;abstract void p
16、rint(String txt);void showMyType()System.out.println("My Type is:"+printerType);abstract class InkPrinter extends PrinterInkPrinter(String inkPrinterType)super(inkPrinterType);void print(String txt)System.out.println("I am Ink Printer");System.out.println("Start to Print:"+txt);class LasertPrinter extends PrinterLasert
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江省強(qiáng)基聯(lián)盟2024-2025學(xué)年高二下學(xué)期4月聯(lián)考(期中)政治試題(含答案)
- 紡織品創(chuàng)新材料及檢測(cè)試題及答案
- 2024廣告設(shè)計(jì)師職業(yè)路徑探索試題及答案
- 2025年香糟雞項(xiàng)目市場(chǎng)調(diào)查研究報(bào)告
- 華麗轉(zhuǎn)身的2024年國(guó)際商業(yè)美術(shù)設(shè)計(jì)師考試試題及答案
- 2025年踏步梯項(xiàng)目市場(chǎng)調(diào)查研究報(bào)告
- 2025年電子口袋秤項(xiàng)目市場(chǎng)調(diào)查研究報(bào)告
- 助理廣告師試題及答案全面支持
- 剝離力測(cè)試題及答案
- 紡織檢驗(yàn)員工作流程梳理試題及答案
- 指導(dǎo)腎性貧血患者自我管理的中國(guó)專家共識(shí)(2024版)解讀課件
- 2023年新課標(biāo)全國(guó)ⅰ卷英語(yǔ)真題(解析)
- 公共管理學(xué)方法論知到智慧樹章節(jié)測(cè)試課后答案2024年秋華南農(nóng)業(yè)大學(xué)
- 《家禽飼養(yǎng)方式》課件
- 《裝配式碳纖維增強(qiáng)免拆底模鋼筋桁架樓承板(HF)應(yīng)用技術(shù)標(biāo)準(zhǔn)》
- 人工智能在機(jī)能學(xué)實(shí)驗(yàn)教學(xué)應(yīng)用圖景的構(gòu)設(shè)與挑戰(zhàn)
- Unit 6 Beautiful landscapes Integration說課稿 - 2024-2025學(xué)年譯林版英語(yǔ)七年級(jí)下冊(cè)
- 2025年上半年廣東省中山市南頭鎮(zhèn)人民政府招聘3人易考易錯(cuò)模擬試題(共500題)試卷后附參考答案
- 煤礦安全用電培訓(xùn)課件
- 2024年度衛(wèi)浴企業(yè)數(shù)字化轉(zhuǎn)型戰(zhàn)略咨詢合同3篇
- 社區(qū)體檢合同范例
評(píng)論
0/150
提交評(píng)論