




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、.課程設(shè)計報告一、完成XXX銀行模擬ATM機系統(tǒng)的各項功能,做到跳轉(zhuǎn)準確無誤(1)分析主要有5個類,即Account(賬戶類);SaveAccount(儲蓄賬戶類):不能透支;CreditAccount(信用賬戶類):可以透支;Bank(銀行類);ATM(ATM類)可以實現(xiàn)數(shù)據(jù)保存功能,數(shù)據(jù)將保存在文件。主要功能有:1.開戶2.查詢賬戶余額 3.存款 4.取款 5.轉(zhuǎn)賬(一個賬戶到另一個賬戶)等(2)源程序package ATM;/* * 銀行賬戶類 */public abstract class Account private long id; /銀行卡號 private String pa
2、ssword; /密碼 private String name; /姓名 private String personId; /身份證 private int accountType; /賬戶類型(0,儲蓄 1,信用卡) private double balance; /賬戶金額 public Account()/無參構(gòu)造方法 super(); public Account(long id,String password,String name,String personId,int accountType,double balance) super(); this.id = id; this.
3、password = password; = name; this.personId = personId; this.accountType = accountType; this.balance = balance; public long getId() return id;public void setId(long id) this.id = id;public String getPassword() return password;public void setPassword(String password) this.password = password
4、;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 accountType) this.account
5、Type = accountType;public double getBalance() return balance;public void setBalance(double balance) this.balance = balance;/存款public void deposit(double money)balance = balance + money;public abstract void withdraw(double money); package ATM;/* * 信用卡用戶 * */public class CreditAccount extends Account
6、private double ceiling;public CreditAccount()public CreditAccount(long id, String password, String name, String personId, int accountType, double balance,double ceiling) super(id, password, name, personId, accountType, balance);this.ceiling = ceiling; public double getCeiling() return ceiling;public
7、 void setCeiling(double ceiling) this.ceiling = ceiling;Overridepublic void withdraw(double money) / TODO Auto-generated method stubif (getBalance()+ceilingmoney)System.out.println(對不起,已超出您的信用額度!);elsesetBalance(getBalance()-money);package ATM;/* * 儲蓄卡用戶 * */public class SavingAccount extends Accoun
8、tpublic SavingAccount()super(); public SavingAccount(long id, String password, String name, String personId, int accountType, double balance) super(id, password, name, personId, accountType, balance);/ TODO Auto-generated constructor stubOverridepublic void withdraw(double money) / TODO Auto-generat
9、ed method stubif (getBalance()money)System.out.println(對不起,您的賬戶余額不足!);elsesetBalance(getBalance()-money);package ATM;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.Reader;im
10、port java.io.Writer;public class Bank / 聲明一個銀行賬戶類數(shù)組,用來存放所有的銀行賬戶信息Account accounts = new Account20;int number = 0; / 賬戶數(shù)目int id = 1001; / 銀行卡號從1001開始自動加1;BufferedReader br = null;/ 創(chuàng)建文件,并實現(xiàn)文件的讀取Bank() File file = new File(account.txt);try file.createNewFile();Reader r = new FileReader(file);br = new
11、BufferedReader(r);String s = br.readLine();while (s != null) String str = s.split(,); / split將一個字符串按照某一個特定的分隔符進行拆分/ 判斷是否為儲蓄卡if (str4.equals(0) Account savingAcc = new SavingAccount(Long.parseLong(str0), str1, str2, str3,Integer.parseInt(str4), Double.parseDouble(str5); / 將str數(shù)組中的所有信息存入儲蓄賬戶中accountsn
12、umber = savingAcc; else CreditAccount creditAcc = new CreditAccount(Long.parseLong(str0), str1, str2, str3,Integer.parseInt(str4), Double.parseDouble(str5), 5000);accountsnumber = creditAcc;number+;id+;s = br.readLine(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); fin
13、ally try if (br != null) br.close(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();public Account getAccounts() return accounts;public void setAccounts(Account accounts) this.accounts = accounts;public int getNumber() return number;public void setNumber(int number) this.
14、number = number;public int getId() return id;public void setId(int id) this.id = id;/* * 登錄驗證 */public Account verifyAccount(long id, String password) / 傳遞賬號和密碼進入登入驗證,為了后續(xù)功能,返回登錄賬戶對象Account account = null;for (int i = 0; i accounts.length; i+) / 如果賬戶存在if (accountsi != null) / 驗證賬號和密碼if (id = account
15、si.getId() & password.equals(accountsi.getPassword() account = accountsi;break; else System.out.println(對不起,您輸入的賬戶或用戶名有誤!請重新輸入!n);break;return account;/* * 開戶 * */public Account openAccount(String passwd1, String passwd2, String name, String personId, int type) Account account = null; / 創(chuàng)建一個新賬戶if (p
16、asswd1.equals(passwd2) / 判斷兩個次密碼是否一樣if (type = 1) / 判斷用戶類型/ 令信用額度為5000,賬戶余額為0account = new CreditAccount(id, passwd1, name, personId, type, 0, 5000); else account = new SavingAccount(id, passwd1, name, personId, type, 0);accountsnumber = account; /把開戶的信息存到 銀行賬戶類數(shù)組System.out.println(開戶成功!賬戶信息如下);Syst
17、em.out.println(您的卡號為: + id + n您的密碼為: + passwd1 + n您的戶名為: + name + n您的身份證號為: + personId+ n您的賬戶類型為: + type);account.setAccountType(type);number+;id+;return account; / 開戶成功,返回賬戶對象 else System.out.println(對不起,您兩次密碼輸入不匹配);return null;/* * 轉(zhuǎn)賬驗證 */public Account verifyAccount(long id) Account account = nul
18、l;for (int i = 0; i accounts.length; i+) / 如果賬戶存在if (accountsi != null) / 驗證賬號和密碼if (id = accountsi.getId() account = accountsi;break; else break;return account;/* * 存款 */public void deposit(Account account, double money) account.deposit(money);/* * 取款 */public void withdraw(Account account, double
19、money) account.withdraw(money);public void kaihu(Account account) /* * 轉(zhuǎn)賬 */public void transfer(Account account1, Account account2, double money) account1.withdraw(money);account2.deposit(money);/* * 保存數(shù)據(jù),用到IO流,將數(shù)據(jù)保存到記事本 */public void save() File file = new File(account.txt);BufferedWriter bw = nul
20、l;try Writer w = new FileWriter(file);bw = new BufferedWriter(w);for (int i = 0; i accounts.length; i+) if (accountsi != null) / 將賬戶信息(6項)寫入account.txt中bw.write(accountsi.getId() + ,);bw.write(accountsi.getPassword() + ,);bw.write(accountsi.getName() + ,);bw.write(accountsi.getPersonId() + ,);bw.wri
21、te(accountsi.getAccountType() + ,);bw.write(Double.toString(accountsi.getBalance(); bw.newLine(); elsebreak;bw.flush(); / 刷新緩存區(qū) catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace(); finally try bw.close(); catch (IOException e) e.printStackTrace();/測試類package ATM;import java.ut
22、il.Scanner;public class Test_ATM public static void main(String args) / TODO Auto-generated method stubScanner in = new Scanner(System.in);Bank bank = new Bank();boolean flag = true; /退出程序的標志while (flag) System.out.println(*歡迎使用XXX銀行模擬ATM系統(tǒng),請按如下步驟操作*);System.out.println( *1.用已有賬戶登錄);System.out.print
23、ln( *2.沒有賬戶,開戶);System.out.println( *3.退出);System.out.print(請選擇:);int choice1 = in.nextInt();switch (choice1) case 1:System.out.print(請輸入銀行卡號:);long id = in.nextLong();System.out.print(請輸入銀行密碼:);String password = in.next();Account account = bank.verifyAccount(id, password);if (account != null) boole
24、an flag1 = true; / 退出二級菜單的循環(huán)標志while (flag1) System.out.println(*歡迎使用XXX銀行模擬ATM系統(tǒng),請按如下步驟操作*);System.out.println( *1.查詢賬戶余額);System.out.println( *2.存款);System.out.println( *3.取款);System.out.println( *4.轉(zhuǎn)賬);System.out.println( *5.退卡);System.out.print(請選擇:);int choice2 = in.nextInt();switch (choice2) ca
25、se 1:System.out.print(您賬戶的當前余額為: + account.getBalance() + n);break;case 2:System.out.print(請輸入您的存款金額:);double money1 = in.nextDouble();bank.deposit(account, money1);break;case 3:System.out.print(請輸入您的取款金額:);double money2 = in.nextDouble();bank.withdraw(account, money2);break;case 4:System.out.printl
26、n(請輸入您要轉(zhuǎn)入賬戶的卡號:);long id2 = in.nextLong();Account account2 = bank.verifyAccount(id2);if (account2 != null) System.out.println(請輸入您要轉(zhuǎn)入的金額:);double money = in.nextDouble();if (money = account.getBalance() bank.transfer(account, account2, money);System.out.println(轉(zhuǎn)賬成功!); else System.out.println(抱歉,您賬戶
27、沒有足夠的余額!); else System.out.println(抱歉,你輸入的賬戶不存在!);break;case 5:flag1 = false;System.out.println(請取回您的銀行卡!);break;default:System.out.println(沒有該選項,請重新選擇!);break;break;case 2:System.out.print(請輸入賬戶密碼:);String password1 = in.next();System.out.print(請在輸入賬戶密碼:);String password2 = in.next();System.out.pri
28、nt(請輸入戶主姓名:);String name = in.next();System.out.print(請輸入戶主身份證號碼:);String personId = in.next();System.out.print(請輸入賬戶類型(0儲蓄卡,1信用卡));int type = in.nextInt();bank.openAccount(password1, password2, name, personId, type);break;case 3:bank.save(); /保存數(shù)據(jù)System.out.println(謝謝使用!);flag = false;break;default
29、:break;(3)調(diào)試結(jié)果(4)小結(jié)在編寫銀行類的中充分的利用了課堂所學(xué)的知識如I/O的輸入輸出、面向?qū)ο蟆?等等在編寫的時候?qū)W習(xí)到了這些知識如何靈活的應(yīng)用,比如在編寫開戶和賬戶驗證方法的時候,這些方法的類型都是“Account”類的類型所以它的返回值是一個對象而不是以前的數(shù)據(jù)類型。二、制作學(xué)生信息管理系統(tǒng)(實現(xiàn)增刪改查操作)(1)分析創(chuàng)建學(xué)生類Student設(shè)置有private屬性的學(xué)號、姓名、出身年月、籍貫、入學(xué)時間、所屬系部成員變量,并實現(xiàn)set的get方法,重寫toString()的方法,創(chuàng)建一個用來管理學(xué)生的類Admin,有刷新學(xué)生數(shù)據(jù)的print方法,判斷學(xué)生是否存在的exist
30、方法,添加學(xué)生的Create方法,查詢學(xué)生的find方法,更新學(xué)生的update方法,刪除學(xué)生的delete方法;通過while()首先輸出實現(xiàn)學(xué)生管理系統(tǒng)的基本功能選項,再添加一個while()用if()判斷用于執(zhí)行各個功能選項,添加學(xué)生的操作,用public void Create(int num, String name, String age, String origin, String time, String academy, Student arr)方法添加學(xué)生。輸入“2”時進入查詢學(xué)生信息的操作,adminStu.find(num, stuArr)進入find方法判斷輸入的學(xué)號
31、是否存在,如果存在則輸出對應(yīng)的學(xué)生信息,否則提示沒有這個學(xué)生的存在,進入是否繼續(xù)查找學(xué)生信息?是(y/Y)否(n/N)操作;輸入“3”時進入執(zhí)行更新學(xué)員的基本信息操作,adminStu.print(stuArr) 輸出所有學(xué)生信息,輸入學(xué)號進行查詢,adminStu.update(num, newNum, newName, newAge, newOrigin, newTime, newAcademy, stuArr)更新學(xué)生基本信息,更改完后將學(xué)生信息輸出顯示。輸入“4”執(zhí)行刪除學(xué)生操作,先輸出顯示所有學(xué)生信息,再按照提示輸入要刪除的學(xué)號,是(y/Y)否(n/N)確認刪除,adminStu.d
32、elete(num, stuArr)刪除學(xué)生信息;確認刪除后列出刪除后學(xué)生信息。(2)源程序package 學(xué)生信息管理系統(tǒng);import java.util.Scanner;public class Student private int Num;/ 學(xué)號private String Name;/ 姓名private String Age;/ 出身年月private String Origin; / 籍貫private String Time;/ 入學(xué)時間private String Academy;/ 所屬系部public int getNum() return Num;public vo
33、id setNum(int num) this.Num = num;public String getName() return Name;public void setName(String name) this.Name = name;public String getAge() return Age;public void setAge(String age) this.Age = age;public String getOrigin() return Origin;public void setOrigin(String origin) Origin = origin;public
34、String getTime() return Time;public void setTime(String time) Time = time;public String getAcademy() return Academy;public void setAcademy(String academy) Academy = academy;public String toString() / 重寫toString方法String str = this.Num + t + this.Name + t + this.Age + t + this.Origin + t + this.Time +
35、 t+ this.Academy + t;return str;package 學(xué)生信息管理系統(tǒng);/* * 用來管理學(xué)生的一個類 */public class Admin String msg = 學(xué)號t姓名t出身年月t籍貫t入學(xué)時間t所屬院系;public void print(Student arr) / 刷新數(shù)據(jù)的方法System.out.println(msg);for (int i = 0; i arr.length; i+) if (arri != null) System.out.println(arri);public boolean exist(int num, Studen
36、t stu) / 判斷學(xué)生是否存在的方法if (stu != null) if (stu.getNum() = num) return true; else return false;return false; /* * 添加學(xué)生的方法 * */public void Create(int num, String name, String age, String origin, String time, String academy, Student arr) Student stu = new Student();stu.setNum(num);stu.setName(name);stu.s
37、etAge(age);stu.setOrigin(origin);stu.setTime(time);stu.setAcademy(academy);System.out.println(-添加學(xué)生信息成功!-);int i = this.setIndex(arr);if (i = 99) System.out.println(學(xué)生人數(shù)已添滿,不能再添加了); else arri = stu;this.print(arr);public int setIndex(Student arr) / 返回數(shù)組為空的下標for (int i = 0; i arr.length; i+) if (arri
38、 = null) return i;return 99;/* *更新學(xué)生信息時查詢學(xué)生的方法 */public boolean updatefind(int num, Student arr) for (int i = 0; i arr.length; i+) if (this.exist(num, arri) = true) / 判斷學(xué)生是否存在return true;return false;public void find(int num, Student arr) / 查詢學(xué)生的方法for (int i = 0; i arr.length; i+) if (this.exist(num
39、, arri) = true) / 判斷學(xué)生是否存在System.out.println(msg);System.out.println(arri);return;System.out.println(-沒有這個學(xué)生的存在-);public void update(int num,int newNum, String newName, String newAge, String newOrigin, String newTime, String newAcademy, Student arr) / 更新學(xué)生基本信息的方法for (int i = 0; i arr.length; i+) arr
40、i.setNum(newNum);arri.setName(newName);arri.setAge(newAge);arri.setOrigin(newOrigin);arri.setTime(newTime);arri.setAcademy(newAcademy);System.out.println(-修改學(xué)生信息成功!-);this.print(arr);break;public void delete(int num, Student arr) / 刪除學(xué)生的方法for (int i = 0; i arr.length; i+) if (this.exist(num, arri) a
41、rri = null;this.print(arr);System.out.println(-刪除學(xué)生信息成功!-);return;System.out.println(您所指定學(xué)號的學(xué)生不存在);package 學(xué)生信息管理系統(tǒng);import java.util.Scanner;public class Test public static void main(String args) Scanner in = new Scanner(System.in);System.out.println(*n學(xué)生信息管理系統(tǒng)n*);System.out.println(歡迎使用!n);Student
42、stuArr = new Student20;/ 定義學(xué)生的人數(shù)Admin adminStu = new Admin();while (true) System.out.println(-學(xué)生學(xué)籍管理系統(tǒng)-);System.out.println(ttt1:添加);System.out.println(ttt2:查詢);System.out.println(ttt3:修改);System.out.println(ttt4:刪除);System.out.println(ttt0:退出系統(tǒng));System.out.println(請選擇你要執(zhí)行的功能:);String number = in.ne
43、xt();while (true) if (number.equals(1) System.out.println(歡迎使用學(xué)籍查詢系統(tǒng));System.out.println(請按如下提示輸入需要添加的學(xué)生信息(兩個數(shù)據(jù)之間用tab鍵隔開);System.out.println(adminStu.msg);int num = in.nextInt();String name = in.next();String age = in.next();String origin = in.next();String time = in.next();String academy = in.next(
44、);adminStu.Create(num, name, age, origin, time, academy, stuArr);/ 添加學(xué)生System.out.println(是否繼續(xù)錄入學(xué)生信息?是(y/Y)否(n/N));String s = in.next();if (s.equals(y) | (s.equals(Y) continue; else if (s.equals(n) | (s.equals(N) break; elseSystem.out.println(輸入有誤!);break; else if (number.equals(2) System.out.printl
45、n(執(zhí)行查詢學(xué)生基本信息的操作);System.out.println(請輸入學(xué)生的學(xué)號進行查找:);int num = in.nextInt();adminStu.find(num, stuArr);System.out.println(是否繼續(xù)查找學(xué)生信息?是(y/Y)否(n/N));String s = in.next();if (s.equals(y) | (s.equals(Y) continue; else if (s.equals(n) | (s.equals(N) break; elseSystem.out.println(輸入有誤!);break; else if (number.equals(3) System.out.println(執(zhí)行更新學(xué)員的基本信息操作);adminStu.print(stuArr);/ 輸出所有學(xué)生信息System.out.println(請輸入學(xué)生的學(xué)號:);int num = in.nex
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 運動類視頻拍攝與剪輯要點
- 陜西2025年01月陜西省黃龍縣人民政府辦公室2025年公開遴選6名工作人員筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 遺傳病診斷與治療的新進展及未來趨勢
- 金融行業(yè)市場調(diào)研方法探討
- 跨國公司如何優(yōu)化投資組合
- 運動健康產(chǎn)業(yè)的創(chuàng)新發(fā)展與市場潛力探討
- 貴州企業(yè)招聘2024岑鞏縣潤祥勞務(wù)派遣服務(wù)有限責(zé)任公司招聘筆試參考題庫附帶答案詳解
- 湖北2025年01月湖北省黃岡市直事業(yè)單位2025年引進133名人才筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 跨文化背景下的消費者心理與營銷策略
- 浙江國企招聘2025寧波象山縣水務(wù)集團有限公司第一期招聘8人筆試參考題庫附帶答案詳解
- 2024年環(huán)北部灣廣西水資源配置有限公司招聘考試真題
- 2025年黑龍江建筑職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫完美版
- 上海市建設(shè)工程施工圖設(shè)計文件勘察設(shè)計質(zhì)量疑難問題匯編(2024 版)
- 第一單元時、分、秒(說課稿)-2024-2025學(xué)年三年級上冊數(shù)學(xué)人教版
- 地理-浙江省杭州八縣市2024學(xué)年高二第一學(xué)期期末學(xué)業(yè)水平測試試題和答案
- 《康復(fù)工程學(xué)》課件-第一講 康復(fù)工程概論
- DeepSeek:從入門到精通
- 天津2025年天津中德應(yīng)用技術(shù)大學(xué)輔導(dǎo)員崗位招聘7人筆試歷年參考題庫附帶答案詳解
- 2025年無錫職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測試近5年??及鎱⒖碱}庫含答案解析
- 2025年銅材拉絲項目可行性研究報告
- 2025四川宜賓市高縣縣屬國企業(yè)第一次招聘3人易考易錯模擬試題(共500題)試卷后附參考答案
評論
0/150
提交評論