




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(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. 編寫(xiě)多態(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) 編寫(xiě)程序模擬個(gè)人銀行賬號(hào)類??紤]個(gè)人銀行的特點(diǎn),建立類模型(注意屬性和方法的訪問(wè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) 編寫(xiě)測(cè)試類,完成如下(1)中類方法的測(cè)試實(shí)現(xiàn)如下業(yè)務(wù):開(kāi)戶,存款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) 按如下類圖編寫(xiě)代碼 參考代碼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) 編寫(xiě)測(cè)試類并創(chuàng)建main()方法,完成如下操作A 分別創(chuàng)建Person、Student、Teacher對(duì)象,完成屬性和每個(gè)方法的調(diào)用測(cè)試B 在Student和Teacher中完成eat()方法的重寫(xiě)
11、C 編寫(xiě)類型轉(zhuǎn)化示例(向上類型轉(zhuǎn)化、向下類型轉(zhuǎn)化)3. 多態(tài)現(xiàn)象 在完成(2)中Student、Teacher類eat()方法重寫(xiě)后,在測(cè)試類中編寫(xiě)如下代碼并在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. 抽象類的使用編寫(xiě)以上類圖所示類,并編寫(xiě)測(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);編寫(xiě)測(cè)試類及main() 方法,完成如下操作A. 創(chuàng)建Printer,InkPrinter,LaserPrinter類的對(duì)象。B. 設(shè)計(jì)并編寫(xiě)演示多態(tài)現(xiàn)象的代碼5. 接口的使用編寫(xiě)以上類圖的代碼,并編寫(xiě)測(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. 本站所有資源如無(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)學(xué)治療技術(shù)研究進(jìn)展
- 公共安全科學(xué)導(dǎo)論
- 動(dòng)物醫(yī)學(xué)課程旁聽(tīng)指南
- 《臨時(shí)調(diào)整》課件
- 《化妝的藝術(shù)與技巧》課件
- 《Katie De Sousa》上篇:精彩紛呈的課件展示
- 《臥室衣柜規(guī)劃》課件
- 《術(shù)后鎮(zhèn)痛管理策略》課件
- 粉末活動(dòng)策劃方案
- 《心臟驟停、復(fù)蘇》課件
- 礦山施工過(guò)程中的風(fēng)險(xiǎn)控制及預(yù)防措施
- 校長(zhǎng)在初三二模教學(xué)質(zhì)量分析會(huì)上講話明確差距,對(duì)癥下藥,多方聯(lián)動(dòng),分類推進(jìn),奮戰(zhàn)60天
- 民事起訴狀(勞動(dòng)爭(zhēng)議糾紛)
- 酒店前臺(tái)掛賬管理制度
- 船舶ABS規(guī)范培訓(xùn)
- 2025標(biāo)準(zhǔn)裝修合同范本
- 2025年中鐵特貨物流股份有限公司招聘(75人)筆試參考題庫(kù)附帶答案詳解
- 植物生理學(xué)(齊魯師范學(xué)院)知到課后答案智慧樹(shù)章節(jié)測(cè)試答案2025年春齊魯師范學(xué)院
- 北師大版數(shù)學(xué)八年級(jí)下學(xué)期 全等三角形七大模型 知識(shí)梳理+練習(xí) (含解析)
- 指導(dǎo)腎性貧血患者自我管理的中國(guó)專家共識(shí)(2024版)解讀課件
- 2023年新課標(biāo)全國(guó)ⅰ卷英語(yǔ)真題(解析)
評(píng)論
0/150
提交評(píng)論