版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、bam銀行賬戶管理系統(tǒng)(java類) 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! bam銀行賬戶管理系統(tǒng)(atm管理系統(tǒng)) 本系統(tǒng)采納java語言并在eclipse環(huán)境下編寫測試完成,涉及類的概念,以及面對對象的幾大特性(繼承,封裝,多態(tài),抽象),也有特別處理機制,基本可以滿意大多數(shù)bam系統(tǒng)的相關實現(xiàn),且代碼內標注大量解釋,讀者可以很輕松地理解相關規(guī)律,大家可以快樂參考。 系統(tǒng)簡介: 1、java類的面相對象的應用,擁有特別處理機制,不會由于輸入錯誤而導致程序崩潰 2、主要有5個類,即account(賬戶類) saveaccount(儲蓄賬戶類):不能透支 creditaccount
2、(信用賬戶類):可以透支 bank(銀行類) atm(atm類) 類的詳細屬性級行為見代碼 3、各個類之間的相互關系,涉及繼承、封裝、多態(tài)、抽象,在多態(tài)中又涉及重載和重 寫,請讀者留意相關聯(lián)系(關注解釋) 4、可以實現(xiàn)數(shù)據保存功能,數(shù)據將保存在文件中(即當你注冊了一個賬戶,下次再登 陸系統(tǒng)時,可以實現(xiàn)與上次最終的操作相連接) 5、賬戶號自動生成,比較符合現(xiàn)實 6、主要功能有:1.開戶 2.查詢賬戶余額 3.存款 4.取款 5.轉賬(一個賬戶到另一個賬戶)等 7、運行時界面簡示 1.初始界面(賬戶登錄) 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! 2.賬戶登錄后界面 留意事項: 1、本系
3、統(tǒng)采納的編程環(huán)境是jdk1.7,jer7。所以,運行代碼需要保持電腦上所裝的jdk為1.7以上版本,如有報錯,只需換個高一點的版本即可。留意:第一次裝jdk,要配置環(huán)境變量(請查閱相關資料,比較簡潔) 2、本系統(tǒng)代碼涉及到包,所以假如報名不全都就會報錯,解決方法:修改一下包名即可 3、建議把各個類寫在同一個包下面,且每一個類單獨寫一個java文件,如下圖: 4、在運行程序前,需要在項目下面新建一個account.txt(用來保存數(shù)據)文件(如上圖),并在其中寫入至少一個賬戶信息,(如下圖,其中每項代表的意思,請讀者參照代碼內的解釋),否則在初始化的時候會由于找不到賬戶信息,從而產生特別。 符合
4、大多數(shù)atm,bam任務要求,詳細介紹見文檔! 系統(tǒng)源碼: account類 package com.qx;/包名 /* * 賬戶類:包含兩種賬戶類型-1.儲蓄賬戶 2.信用賬戶 */ public abstract class account /屬性 protected long id; protected string password; protected string name; protected string personid; protected int accounttype; protected double balance; /構造方法 public account() s
5、uper(); public account(long id, string password, string name, string personid, int accouttype,double balance) super(); this.id = id; this.password = password; = name; this.personid = personid; 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! this.accounttype = accounttype; this.balance = balance; /getxxx,setxxx方法 public l
6、ong getid() return id; public void setid(long id) this.id = id; public string getpassword() return password; public void setpassword(string password) this.password = password; public string getname() return name; public void setname(string name) = name; public string getpersonid() return personid; p
7、ublic void setpersonid(string personid) this.personid = personid; public int getaccounttype() return accounttype; public void setaccounttype(int accounttype) this.accounttype = accounttype; public double getbalance() return balance; public void setbalance(double balance) this.balance = balance; /* *
8、 存款 */ public void deposit(double money) 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! balance += money; /* * 取款(取款方式由賬戶類型打算,所以設為抽象方法,相應的account類應設為抽象類) */ public abstract void withdraw(double money); savingaccount類 package com.qx; /* * 儲蓄賬戶類 */ public class savingaccount extends account /構造函數(shù) public savingaccount() su
9、per(); public savingaccount(long id, string password, string name, string personid,int accounttype, double balance) super(id, password, name, personid, accounttype, balance); /對父類的withdraw()實現(xiàn) public void withdraw(double money) if(balance money) system.out.println(對不起,賬戶余額不足!); else balance -= money
10、; 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! cresitaccount類 package com.qx; /* * 信用賬戶類,增加一個信用額度ceiling屬性 */ public class creditaccount extends account private int ceiling; /構造函數(shù) public creditaccount() super(); public creditaccount(long id, string password, string name, string personid,int accounttype, double balance
11、, int ceiling) super(id, password, name, personid, accounttype, balance); this.ceiling = ceiling; /getxxx,setxxx方法 public int getceiling() return ceiling; public void setceiling(int ceiling) this.ceiling = ceiling; /實現(xiàn)父類的withdraw() public void withdraw(double money) if(balance + ceiling) money) syst
12、em.out.println(對不起,已超出您的信用額度!); else balance -= money; 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! bank類 package com.qx; import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.file; import java.io.filenotfoundexception; import java.io.filereader; import java.io.filewriter; import java.io.ioexcep
13、tion; import java.util.properties; /* * bank類 * 編寫bank類,屬性: 1.當前全部的賬戶對象的集合,存放在數(shù)組中 2.當前賬戶數(shù)量 方法: 1.用戶開戶,需要的參數(shù):id,密碼,密碼確認,姓名,身份證號碼,賬戶類型,返回新創(chuàng)建的account對象的賬號, 提示:用s1.equals(s2) 可以比較s1,s2兩個字符串的值是否相等.賬戶類型是一個整數(shù),為0的時候表示儲蓄賬戶,為1的時候表示信用賬戶 2.用戶登錄,參數(shù):id,密碼 返回登錄賬戶的賬號 3.用戶存款,參數(shù):id,存款數(shù)額,返回void 4.用戶取款,參數(shù):id,取款數(shù)額,返回voi
14、d 5.查詢余額,參數(shù):id,返回該賬戶的余額 double 用戶會通過調用bank對象以上的方法來操作自己的賬戶,請分析各個方法需要的參數(shù) */ public class bank private account accounts = new account20; private int number;/賬戶數(shù)目 private int id = 1001;/確定銀行賬號從1001開頭生成,即第一個賬戶的賬號是1001 /構造函數(shù) public bank() accounts=new account20;/以后不足時擴容。 number = 0; bufferedreader bufread
15、er = null; properties props=system.getproperties(); string path=props.getproperty(user.dir); try bufreader=new bufferedreader(new filereader(new file(path,account.txt); string s = bufreader.readline(); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! string str = s.split(,); if(str4.equals(0) account savingacc = new savin
16、gaccount(long.parselong(str0), str1.tostring(), str2.tostring(), str3.tostring(),integer.parseint(str4), double.parsedouble(str5); accountsnumber = savingacc; else account creditacc = new creditaccount(long.parselong(str0), str1.tostring(), str2.tostring(), str3.tostring(),integer.parseint(str4), do
17、uble.parsedouble(str5),5000); accountsnumber = creditacc; number +; id+; s = bufreader.readline(); catch (numberformatexception e) / todo auto-generated catch block e.printstacktrace(); catch (filenotfoundexception e) / todo auto-generated catch block e.printstacktrace(); catch (ioexception e) / tod
18、o auto-generated catch block e.printstacktrace(); finally try if(bufreader != null) bufreader.close(); catch (ioexception e) / todo auto-generated catch block e.printstacktrace(); /getxxx,setxxx 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! return accounts; public void setaccounts(account accounts) this.accounts = acco
19、unts; public int getnumber() return number; public void setnumber(int number) this.number = number; public int getid() return id; public void setid(int id) this.id = id; /* * 開戶 */ public account openaccount(string passwd1, string passwd2, string name, string personid, int type) /創(chuàng)建一個新賬戶 account acc
20、ount = null; /推斷兩次密碼是否全都 if(passwd1.equals(passwd2) /若全都,再推斷賬戶類型(依據type的值) if(type = 1) /可令開頭余額為10,信用額度為5000 account = new creditaccount(id, passwd1, name, personid, type, 10, 5000); else account = new savingaccount(id, passwd1, name, personid, type, 10); /將賬戶存入賬戶數(shù)組accounts中 /推斷是否超出存儲空間 if(number =
21、accounts.length) /擴容 account newaccounts = new accountaccounts.length*2; /copy原來的相關數(shù)據 system.arraycopy(accounts, 0, newaccounts, 0, accounts.length); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! /將newaccounts賦給accounts accounts = newaccounts; accountsnumber = account; else accountsnumber = account; system.out.println(
22、開戶勝利!賬戶信息見下); system.out.println(您的卡號為:+id+n+您的密碼為:+passwd1+n+您的戶名為:+name+n +您的身份證號為:+personid+n+您的賬戶類型為:+type+n); account.accounttype = type; number+; id+; return account;/此時開戶勝利 else system.out.println(對不起!您兩次密碼輸入不匹配,開戶失敗!); return null;/此時開戶失敗 /* * 保存數(shù)據 */ public void saveaccountdate() bufferedwr
23、iter bufwriter=null; try properties props=system.getproperties(); string path=props.getproperty(user.dir); bufwriter=new bufferedwriter(new filewriter(new file(path,account.txt); for(int i = 0;i accounts.length;i+) /若存在賬戶 if(accountsi != null) /寫入賬戶信息到account.txt bufwriter.write(accountsi.id+,); buf
24、writer.write(accountsi.getpassword()+,); bufwriter.write(accountsi.getname()+,); bufwriter.write(accountsi.getpersonid()+,); bufwriter.write(accountsi.getaccounttype()+,); bufwriter.write(double.tostring(accountsi.getbalance(); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! /* else break; bufwriter.flush();/清空緩存中的內容 cat
25、ch (ioexception e) / todo auto-generated catch block e.printstacktrace(); finally try if(bufwriter!=null) bufwriter.close(); catch (ioexception e) / todo auto-generated catch block e.printstacktrace(); * 登錄驗證 */ public account verifyaccount(long id, string password) account account = null; for(int i
26、 = 0;i accounts.length;i+) /若存在賬戶 if(accountsi != null) /驗證id號和password if(id = accountsi.getid() password.equals(accountsi.getpassword() account = accountsi; break; else break; return account; 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! /* * 轉賬驗證(方法的重載) */ public account verifyaccount(long id) account account = null
27、; for(int i = 0;i accounts.length;i+) /若存在賬戶 if(accountsi != null) /* /驗證id號和password if(id = accountsi.getid() account = accountsi; break; else break; return account; * 轉賬 */ public void transferaccount(account account1, account account2, double money) account1.withdraw(money); account2.deposit(mon
28、ey); /* * 存款 */ public void deposit(account account, double money) account.deposit(money); /* * 取款 */ public void withdraw(account account, double money) account.withdraw(money); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! atm類 package com.qx; import java.io.bufferedreader; import java.io.bufferedwriter; import java.
29、io.file; import java.io.filereader; import java.io.filewriter; import java.util.properties; import java.util.scanner; /* * atm類,供應用戶界面操作 */ public class atm /屬性 private bank bank; /構造函數(shù) public atm() bank = new bank(); /main方法 public static void main(string args) atm atm = new atm();/實例化atm bank bank
30、 = atm.bank; /標號,推斷是否退出一級菜單 boolean firstflag = true; while(firstflag) /一級菜單 system.out.println(*歡迎使用xxx銀行模擬atm系統(tǒng),請按如下步驟操作*); system.out.println( *1.用已有賬戶登錄); system.out.println( *2.沒有賬戶,開戶); system.out.println( *3.退出); scanner scanner = new scanner(system.in); system.out.print(請選擇:); try int choice
31、1 = scanner.nextint(); switch(choice1) case 1: scanner = new scanner(system.in); system.out.print(請輸入銀行卡號:); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! long id = scanner.nextint(); scanner = new scanner(system.in); system.out.print(請輸入銀行密碼:); string password = scanner.next(); account account = bank.verifyaccount(id,
32、 password); if(account != null) /標號,推斷是否退出二級菜單 boolean secondflag = true; while(secondflag) /二級菜單 system.out.println(*歡迎使用xxx銀行模擬atm系統(tǒng),請按如下步驟操作*); system.out.println( *1.查詢賬戶余額); system.out.println( *2.存款); system.out.println( *3.取款); system.out.println( *4.轉賬); system.out.println( *5.退卡); scanner =
33、 new scanner(system.in); system.out.print(請選擇:); try int choice2 = scanner.nextint(); switch(choice2) case 1: +account.getbalance(); system.out.println(您賬戶的當前余額為: break; case 2: scanner = new scanner(system.in); system.out.print(請輸入您的存款金額:); double money1 = scanner.nextdouble(); bank.deposit(account
34、, money1); break; case 3: scanner = new scanner(system.in); system.out.print(請輸入您的取款金額:); double money2 = scanner.nextdouble(); bank.withdraw(account, money2); break; case 4: scanner = new scanner(system.in); system.out.print(請輸入您要轉入賬戶的卡號:); long id2 = scanner.nextlong(); account account2 = bank.verifyaccount(id2); 符合大多數(shù)atm,bam任務要求,詳細介紹見文檔! 額:); money); if(account2 != null) scanner = new scanner(system.in); system.out.print(請輸入您要轉入賬戶的金 double money = scanner.nextlong(); if(money = account.balance) bank.transfera
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版門診設備設施租賃與承包合同4篇
- 2025年度航空航天零部件加工與供應分包合同3篇
- 二零二五年度離婚財產分割與子女撫養(yǎng)權分配合同4篇
- 2025年度美團特色團購合作合同范本細則4篇
- 2 24-全國護理專業(yè)教學 資源庫-1738309514230
- 診斷與改進“應知應會”50問
- 2025年度特色培訓學校股份合作發(fā)展合同3篇
- 2025年度校園春游活動團隊旅游合同
- 二零二五年企業(yè)員工出差通訊費用報銷及標準合同3篇
- 2025年度個人信用借款合同隱私保護措施2篇
- 三年級數(shù)學(上)計算題專項練習附答案
- 中醫(yī)診療方案腎病科
- 2025年安慶港華燃氣限公司招聘工作人員14人高頻重點提升(共500題)附帶答案詳解
- 人教版(2025新版)七年級下冊數(shù)學第七章 相交線與平行線 單元測試卷(含答案)
- 中藥飲片培訓課件
- 醫(yī)院護理培訓課件:《早產兒姿勢管理與擺位》
- 《論文的寫作技巧》課件
- 空氣自動站儀器運營維護項目操作說明以及簡單故障處理
- 2022年12月Python-一級等級考試真題(附答案-解析)
- T-CHSA 020-2023 上頜骨缺損手術功能修復重建的專家共識
- Hypermesh lsdyna轉動副連接課件完整版
評論
0/150
提交評論