




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、BAM銀行賬戶管理系統(tǒng)(ATM管理系統(tǒng))本系統(tǒng)采用JAVA語(yǔ)言并在eclipse環(huán)境下編寫(xiě)測(cè)試完成,涉及類(lèi)的概念,以及面向?qū)ο蟮膸状筇匦裕ɡ^承,封裝,多態(tài),抽象),也有異常處理機(jī)制,基本可以滿足大多數(shù)BAM系統(tǒng)的相關(guān)實(shí)現(xiàn),且代碼內(nèi)標(biāo)注大量注釋,讀者可以很輕松地理解相關(guān)邏輯,大家可以開(kāi)心參考。系統(tǒng)簡(jiǎn)介:1、JAVA類(lèi)的面相對(duì)象的應(yīng)用,擁有異常處理機(jī)制,不會(huì)因?yàn)檩斎脲e(cuò)誤而導(dǎo)致程序崩潰2、主要有5個(gè)類(lèi),即Account(賬戶類(lèi))SaveAccount(儲(chǔ)蓄賬戶類(lèi)):不能透支CreditAccount(信用賬戶類(lèi)):可以透支Bank(銀行類(lèi))ATM(ATM類(lèi)) 類(lèi)的具體屬性級(jí)行為見(jiàn)代碼 3、各個(gè)類(lèi)之間
2、的相互關(guān)系,涉及繼承、封裝、多態(tài)、抽象,在多態(tài)中又涉及重載和重 寫(xiě),請(qǐng)讀者注意相關(guān)聯(lián)系(關(guān)注注釋) 4、可以實(shí)現(xiàn)數(shù)據(jù)保存功能,數(shù)據(jù)將保存在文件中(即當(dāng)你注冊(cè)了一個(gè)賬戶,下次再登 陸系統(tǒng)時(shí),可以實(shí)現(xiàn)與上次最后的操作相銜接) 5、賬戶號(hào)自動(dòng)生成,比較符合現(xiàn)實(shí) 6、主要功能有:1.開(kāi)戶 2.查詢賬戶余額 3.存款 4.取款 5.轉(zhuǎn)賬(一個(gè)賬戶到另一個(gè)賬戶)等 7、運(yùn)行時(shí)界面簡(jiǎn)示1.初始界面(賬戶登錄) 2.賬戶登錄后界面注意事項(xiàng):1、本系統(tǒng)采用的編程環(huán)境是JDK1.7,jer7。所以,運(yùn)行代碼需要保持電腦上所裝的JDK為1.7以上版本,如有報(bào)錯(cuò),只需換個(gè)高一點(diǎn)的版本即可。注意:第一次裝JDK,要配置
3、環(huán)境變量(請(qǐng)查閱相關(guān)資料,比較簡(jiǎn)單)2、本系統(tǒng)代碼涉及到包,所以如果報(bào)名不一致就會(huì)報(bào)錯(cuò),解決方法:修改一下包名即可3、建議把各個(gè)類(lèi)寫(xiě)在同一個(gè)包下面,且每一個(gè)類(lèi)單獨(dú)寫(xiě)一個(gè)java文件,如下圖:4、在運(yùn)行程序前,需要在項(xiàng)目下面新建一個(gè)account.txt(用來(lái)保存數(shù)據(jù))文件(如上圖),并在其中寫(xiě)入至少一個(gè)賬戶信息,(如下圖,其中每項(xiàng)代表的意思,請(qǐng)讀者參照代碼內(nèi)的注釋),否則在初始化的時(shí)候會(huì)因?yàn)檎也坏劫~戶信息,從而產(chǎn)生異常。系統(tǒng)源碼:Account類(lèi)package com.qx;/包名/* * 賬戶類(lèi):包含兩種賬戶類(lèi)型->1.儲(chǔ)蓄賬戶 2.信用賬戶 */public abstract cla
4、ss Account /屬性protected long id;protected String password;protected String name;protected String personId;protected int accountType;protected double balance;/構(gòu)造方法public Account()super();public Account(long id, String password, String name, String personId,int accoutType,double balance) super();this.
5、id = id;this.password = password; = name;this.personId = personId;this.accountType = accountType;this.balance = balance;/getXxx,setXxx方法public long getId() return id;public void setId(long id) this.id = id;public String getPassword() return password;public void setPassword(String password)
6、this.password = password;public String getName() return name;public void setName(String name) = name;public String getPersonId() return personId;public void setPersonId(String personId) this.personId = personId;public int getAccountType() return accountType;public void setAccountType(int a
7、ccountType) this.accountType = accountType;public double getBalance() return balance;public void setBalance(double balance) this.balance = balance;/* * 存款 */public void deposit(double money)balance += money;/* * 取款(取款方式由賬戶類(lèi)型決定,所以設(shè)為抽象方法,相應(yīng)的Account類(lèi)應(yīng)設(shè)為抽象類(lèi)) */public abstract void withdraw(double money)
8、;SavingAccount類(lèi)package com.qx;/* * 儲(chǔ)蓄賬戶類(lèi) */public class SavingAccount extends Account /構(gòu)造函數(shù)public SavingAccount() super();public SavingAccount(long id, String password, String name, String personId,int accountType, double balance) super(id, password, name, personId, accountType, balance);/對(duì)父類(lèi)的withdr
9、aw()實(shí)現(xiàn)public void withdraw(double money)if(balance < money)System.out.println("對(duì)不起,賬戶余額不足!");elsebalance -= money;CresitAccount類(lèi)package com.qx;/* * 信用賬戶類(lèi),增加一個(gè)信用額度ceiling屬性 */public class CreditAccount extends Accountprivate int ceiling;/構(gòu)造函數(shù)public CreditAccount()super();public CreditAcc
10、ount(long id, String password, String name,String personId,int accountType, double balance, 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;/
11、實(shí)現(xiàn)父類(lèi)的withdraw()public void withdraw(double money)if(balance + ceiling) < money)System.out.println("對(duì)不起,已超出您的信用額度!");elsebalance -= money;Bank類(lèi)package com.qx;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.i
12、o.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.Properties;/* * Bank類(lèi) * 編寫(xiě)B(tài)ank類(lèi),屬性:1.當(dāng)前所有的賬戶對(duì)象的集合,存放在數(shù)組中2.當(dāng)前賬戶數(shù)量方法:1.用戶開(kāi)戶,需要的參數(shù):id,密碼,密碼確認(rèn),姓名,身份證號(hào)碼,賬戶類(lèi)型,返回新創(chuàng)建的Account對(duì)象的賬號(hào), 提示:用s1.equals(s2) 可以比較s1,s2兩個(gè)字符串的值是否相等.賬戶類(lèi)型是一個(gè)整數(shù),為0的時(shí)候表示儲(chǔ)蓄賬戶,為1的時(shí)候表示信用賬戶2.用戶登錄,參數(shù):id,密碼 返回登錄
13、賬戶的賬號(hào)3.用戶存款,參數(shù):id,存款數(shù)額,返回void4.用戶取款,參數(shù):id,取款數(shù)額,返回void5.查詢余額,參數(shù):id,返回該賬戶的余額 double用戶會(huì)通過(guò)調(diào)用Bank對(duì)象以上的方法來(lái)操作自己的賬戶,請(qǐng)分析各個(gè)方法需要的參數(shù) */public class Bank private Account accounts = new Account20;private int number;/賬戶數(shù)目private int id = 1001;/確定銀行賬號(hào)從1001開(kāi)始生成,即第一個(gè)賬戶的賬號(hào)是1001/構(gòu)造函數(shù)public Bank() accounts=new Account20
14、;/以后不足時(shí)擴(kuò)容。number = 0;BufferedReader bufReader = 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();while(s != null)String str = s.split
15、(",");if(str4.equals("0")Account savingAcc = new SavingAccount(Long.parseLong(str0),str1.toString(), str2.toString(),str3.toString(),Integer.parseInt(str4),Double.parseDouble(str5);accountsnumber = savingAcc;elseAccount creditAcc = new CreditAccount(Long.parseLong(str0),str1.toSt
16、ring(), str2.toString(),str3.toString(),Integer.parseInt(str4),Double.parseDouble(str5),5000);accountsnumber = creditAcc;number +;id+;s = bufReader.readLine(); catch (NumberFormatException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (FileNotFoundException e) / TODO Auto-generated
17、catch blocke.printStackTrace(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry if(bufReader != null)bufReader.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/getXxx,setXxxpublic Account getAccounts() return accounts;public v
18、oid setAccounts(Account accounts) this.accounts = accounts;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;/* * 開(kāi)戶 */public Account openAccount(String passwd1, String passwd2, String name,
19、 String personId, int type)/創(chuàng)建一個(gè)新賬戶Account account = null;/判斷兩次密碼是否一致if(passwd1.equals(passwd2)/若一致,再判斷賬戶類(lèi)型(根據(jù)type的值)if(type = 1)/可令開(kāi)始余額為10,信用額度為5000account = new CreditAccount(id, passwd1, name, personId, type, 10, 5000);elseaccount = new SavingAccount(id, passwd1, name, personId, type, 10);/將賬戶存入賬
20、戶數(shù)組accounts中/判斷是否超出存儲(chǔ)空間if(number >= accounts.length)/擴(kuò)容Account newAccounts = new Accountaccounts.length*2;/copy原來(lái)的相關(guān)數(shù)據(jù)System.arraycopy(accounts, 0, newAccounts, 0, accounts.length);/將newAccounts賦給accountsaccounts = newAccounts;accountsnumber = account;elseaccountsnumber = account;System.out.print
21、ln("開(kāi)戶成功!賬戶信息見(jiàn)下");System.out.println("您的卡號(hào)為:"+id+"n"+"您的密碼為:"+passwd1+"n"+"您的戶名為:"+name+"n"+"您的身份證號(hào)為:"+personId+"n"+"您的賬戶類(lèi)型為:"+type+"n");account.accountType = type;number+;id+;return account
22、;/此時(shí)開(kāi)戶成功elseSystem.out.println("對(duì)不起!您兩次密碼輸入不匹配,開(kāi)戶失??!");return null;/此時(shí)開(kāi)戶失敗/* * 保存數(shù)據(jù) */public void saveAccountDate()BufferedWriter bufWriter=null;try Properties props=System.getProperties();String path=props.getProperty("user.dir");bufWriter=new BufferedWriter(new FileWriter(new F
23、ile(path,"account.txt");for(int i = 0;i < accounts.length;i+)/若存在賬戶if(accountsi != null)/寫(xiě)入賬戶信息到account.txtbufWriter.write(accountsi.id+",");bufWriter.write(accountsi.getPassword()+",");bufWriter.write(accountsi.getName()+",");bufWriter.write(accountsi.getP
24、ersonId()+",");bufWriter.write(accountsi.getAccountType()+",");bufWriter.write(Double.toString(accountsi.getBalance();bufWriter.newLine();elsebreak;bufWriter.flush();/清空緩存中的內(nèi)容 catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();finallytry if(bufWriter!=null
25、)bufWriter.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();/* * 登錄驗(yàn)證 */public Account verifyAccount(long id, String password)Account account = null;for(int i = 0;i < accounts.length;i+)/若存在賬戶if(accountsi != null)/驗(yàn)證id號(hào)和passwordif(id = accountsi.getId() &&am
26、p; password.equals(accountsi.getPassword()account = accountsi;break;elsebreak;return account;/* * 轉(zhuǎn)賬驗(yàn)證(方法的重載) */public Account verifyAccount(long id)Account account = null;for(int i = 0;i < accounts.length;i+)/若存在賬戶if(accountsi != null)/驗(yàn)證id號(hào)和passwordif(id = accountsi.getId()account = accountsi;b
27、reak;elsebreak;return account;/* * 轉(zhuǎn)賬 */public void transferAccount(Account account1, Account account2, double money)account1.withdraw(money);account2.deposit(money);/* * 存款 */public void deposit(Account account, double money)account.deposit(money);/* * 取款 */public void withdraw(Account account, dou
28、ble money)account.withdraw(money);ATM類(lèi)package com.qx;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.util.Properties;import java.util.Scanner;/* * ATM類(lèi),提供用戶界面操作 */public class ATM /屬性private Bank bank;/構(gòu)造
29、函數(shù)public ATM() bank = new Bank();/main方法public static void main(String args)ATM atm = new ATM();/實(shí)例化ATMBank bank = atm.bank;/標(biāo)號(hào),判斷是否退出一級(jí)菜單boolean firstFlag = true;while(firstFlag)/一級(jí)菜單System.out.println("*歡迎使用XXX銀行模擬ATM系統(tǒng),請(qǐng)按如下步驟操作*");System.out.println(" *1.用已有賬戶登錄");System.out.p
30、rintln(" *2.沒(méi)有賬戶,開(kāi)戶");System.out.println(" *3.退出");Scanner scanner = new Scanner(System.in);System.out.print("請(qǐng)選擇:");try int choice1 = scanner.nextInt();switch(choice1)case 1:scanner = new Scanner(System.in);System.out.print("請(qǐng)輸入銀行卡號(hào):");long id = scanner.nextI
31、nt();scanner = new Scanner(System.in);System.out.print("請(qǐng)輸入銀行密碼:");String password = scanner.next();Account account = bank.verifyAccount(id, password);if(account != null)/標(biāo)號(hào),判斷是否退出二級(jí)菜單boolean secondFlag = true;while(secondFlag)/二級(jí)菜單System.out.println("*歡迎使用XXX銀行模擬ATM系統(tǒng),請(qǐng)按如下步驟操作*"
32、);System.out.println(" *1.查詢賬戶余額");System.out.println(" *2.存款");System.out.println(" *3.取款");System.out.println(" *4.轉(zhuǎn)賬");System.out.println(" *5.退卡");scanner = new Scanner(System.in);System.out.print("請(qǐng)選擇:");try int choice2 = scanner.nextI
33、nt();switch(choice2)case 1:System.out.println("您賬戶的當(dāng)前余額為:"+account.getBalance();break;case 2:scanner = new Scanner(System.in);System.out.print("請(qǐng)輸入您的存款金額:");double money1 = scanner.nextDouble();bank.deposit(account, money1);break;case 3:scanner = new Scanner(System.in);System.out
34、.print("請(qǐng)輸入您的取款金額:");double money2 = scanner.nextDouble();bank.withdraw(account, money2);break;case 4:scanner = new Scanner(System.in);System.out.print("請(qǐng)輸入您要轉(zhuǎn)入賬戶的卡號(hào):");long id2 = scanner.nextLong();Account account2 = bank.verifyAccount(id2);if(account2 != null)scanner = new Scanner(System.in);System.out.print("請(qǐng)輸入您要轉(zhuǎn)入賬戶的金額:");double money = scanner.nextLong();if(money <= account.balance)bank.transferAccount(account, account2, money);System.out.println("轉(zhuǎn)賬成功!");elseSystem.out.println(&qu
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國(guó)廢輪胎煉油設(shè)備市場(chǎng)供需格局及未來(lái)發(fā)展趨勢(shì)報(bào)告
- 2025年中國(guó)民族樂(lè)器行業(yè)發(fā)展監(jiān)測(cè)及投資戰(zhàn)略研究報(bào)告
- 基因疾病的遺傳咨詢和家庭管理
- 營(yíng)銷(xiāo)部綜合事務(wù)管理辦法
- 蔡甸區(qū)街道績(jī)效管理辦法
- 街道幼兒園自主管理辦法
- 證監(jiān)會(huì)并購(gòu)重組管理辦法
- 衢江區(qū)礦產(chǎn)開(kāi)采管理辦法
- 西安市民營(yíng)經(jīng)濟(jì)管理辦法
- 西藏自治區(qū)合同管理辦法
- 浙江2025年6月高一學(xué)考模擬歷史試題及答案
- 2025年 杭州市蕭山區(qū)衛(wèi)健系統(tǒng)事業(yè)單位工作人員招聘考試筆試試卷附答案
- 2025年計(jì)算機(jī)程序設(shè)計(jì)考試試卷及答案
- 2025秋一年級(jí)上冊(cè)語(yǔ)文上課課件 4 日月山川
- 2025年中國(guó)離子膜法燒堿行業(yè)市場(chǎng)發(fā)展前景及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 2025年河南省中考數(shù)學(xué)真題含答案
- 人力中介公司管理制度
- 抗精神病藥氯丙嗪講課件
- 機(jī)關(guān)健身房管理制度
- 2025人教英語(yǔ)初中八年級(jí)下冊(cè)期末測(cè)試卷(含答案)
- 財(cái)產(chǎn)保險(xiǎn)理賠答疑手冊(cè)
評(píng)論
0/150
提交評(píng)論