




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、.課程設計報告一、完成XXX銀行模擬ATM機系統的各項功能,做到跳轉準確無誤(1)分析主要有5個類,即Account(賬戶類);SaveAccount(儲蓄賬戶類):不能透支;CreditAccount(信用賬戶類):可以透支;Bank(銀行類);ATM(ATM類)可以實現數據保存功能,數據將保存在文件。主要功能有:1.開戶2.查詢賬戶余額 3.存款 4.取款 5.轉賬(一個賬戶到另一個賬戶)等(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()/無參構造方法 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 / 聲明一個銀行賬戶類數組,用來存放所有的銀行賬戶信息Account accounts = new Account20;int number = 0; / 賬戶數目int id = 1001; / 銀行卡號從1001開始自動加1;BufferedReader br = null;/ 創建文件,并實現文件的讀取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數組中的所有信息存入儲蓄賬戶中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) / 傳遞賬號和密碼進入登入驗證,為了后續功能,返回登錄賬戶對象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; / 創建一個新賬戶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; /把開戶的信息存到 銀行賬戶類數組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;/* * 轉賬驗證 */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) /* * 轉賬 */public void transfer(Account account1, Account account2, double money) account1.withdraw(money);account2.deposit(money);/* * 保存數據,用到IO流,將數據保存到記事本 */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(); / 刷新緩存區 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系統,請按如下步驟操作*);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; / 退出二級菜單的循環標志while (flag1) System.out.println(*歡迎使用XXX銀行模擬ATM系統,請按如下步驟操作*);System.out.println( *1.查詢賬戶余額);System.out.println( *2.存款);System.out.println( *3.取款);System.out.println( *4.轉賬);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(請輸入您要轉入賬戶的卡號:);long id2 = in.nextLong();Account account2 = bank.verifyAccount(id2);if (account2 != null) System.out.println(請輸入您要轉入的金額:);double money = in.nextDouble();if (money = account.getBalance() bank.transfer(account, account2, money);System.out.println(轉賬成功!); 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(); /保存數據System.out.println(謝謝使用!);flag = false;break;default
29、:break;(3)調試結果(4)小結在編寫銀行類的中充分的利用了課堂所學的知識如I/O的輸入輸出、面向對象、 等等在編寫的時候學習到了這些知識如何靈活的應用,比如在編寫開戶和賬戶驗證方法的時候,這些方法的類型都是“Account”類的類型所以它的返回值是一個對象而不是以前的數據類型。二、制作學生信息管理系統(實現增刪改查操作)(1)分析創建學生類Student設置有private屬性的學號、姓名、出身年月、籍貫、入學時間、所屬系部成員變量,并實現set的get方法,重寫toString()的方法,創建一個用來管理學生的類Admin,有刷新學生數據的print方法,判斷學生是否存在的exist
30、方法,添加學生的Create方法,查詢學生的find方法,更新學生的update方法,刪除學生的delete方法;通過while()首先輸出實現學生管理系統的基本功能選項,再添加一個while()用if()判斷用于執行各個功能選項,添加學生的操作,用public void Create(int num, String name, String age, String origin, String time, String academy, Student arr)方法添加學生。輸入“2”時進入查詢學生信息的操作,adminStu.find(num, stuArr)進入find方法判斷輸入的學號
31、是否存在,如果存在則輸出對應的學生信息,否則提示沒有這個學生的存在,進入是否繼續查找學生信息?是(y/Y)否(n/N)操作;輸入“3”時進入執行更新學員的基本信息操作,adminStu.print(stuArr) 輸出所有學生信息,輸入學號進行查詢,adminStu.update(num, newNum, newName, newAge, newOrigin, newTime, newAcademy, stuArr)更新學生基本信息,更改完后將學生信息輸出顯示。輸入“4”執行刪除學生操作,先輸出顯示所有學生信息,再按照提示輸入要刪除的學號,是(y/Y)否(n/N)確認刪除,adminStu.d
32、elete(num, stuArr)刪除學生信息;確認刪除后列出刪除后學生信息。(2)源程序package 學生信息管理系統;import java.util.Scanner;public class Student private int Num;/ 學號private String Name;/ 姓名private String Age;/ 出身年月private String Origin; / 籍貫private String Time;/ 入學時間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 學生信息管理系統;/* * 用來管理學生的一個類 */public class Admin String msg = 學號t姓名t出身年月t籍貫t入學時間t所屬院系;public void print(Student arr) / 刷新數據的方法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) / 判斷學生是否存在的方法if (stu != null) if (stu.getNum() = num) return true; else return false;return false; /* * 添加學生的方法 * */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(-添加學生信息成功!-);int i = this.setIndex(arr);if (i = 99) System.out.println(學生人數已添滿,不能再添加了); else arri = stu;this.print(arr);public int setIndex(Student arr) / 返回數組為空的下標for (int i = 0; i arr.length; i+) if (arri
38、 = null) return i;return 99;/* *更新學生信息時查詢學生的方法 */public boolean updatefind(int num, Student arr) for (int i = 0; i arr.length; i+) if (this.exist(num, arri) = true) / 判斷學生是否存在return true;return false;public void find(int num, Student arr) / 查詢學生的方法for (int i = 0; i arr.length; i+) if (this.exist(num
39、, arri) = true) / 判斷學生是否存在System.out.println(msg);System.out.println(arri);return;System.out.println(-沒有這個學生的存在-);public void update(int num,int newNum, String newName, String newAge, String newOrigin, String newTime, String newAcademy, Student arr) / 更新學生基本信息的方法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(-修改學生信息成功!-);this.print(arr);break;public void delete(int num, Student arr) / 刪除學生的方法for (int i = 0; i arr.length; i+) if (this.exist(num, arri) a
41、rri = null;this.print(arr);System.out.println(-刪除學生信息成功!-);return;System.out.println(您所指定學號的學生不存在);package 學生信息管理系統;import java.util.Scanner;public class Test public static void main(String args) Scanner in = new Scanner(System.in);System.out.println(*n學生信息管理系統n*);System.out.println(歡迎使用!n);Student
42、stuArr = new Student20;/ 定義學生的人數Admin adminStu = new Admin();while (true) System.out.println(-學生學籍管理系統-);System.out.println(ttt1:添加);System.out.println(ttt2:查詢);System.out.println(ttt3:修改);System.out.println(ttt4:刪除);System.out.println(ttt0:退出系統);System.out.println(請選擇你要執行的功能:);String number = in.ne
43、xt();while (true) if (number.equals(1) System.out.println(歡迎使用學籍查詢系統);System.out.println(請按如下提示輸入需要添加的學生信息(兩個數據之間用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);/ 添加學生System.out.println(是否繼續錄入學生信息?是(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(執行查詢學生基本信息的操作);System.out.println(請輸入學生的學號進行查找:);int num = in.nextInt();adminStu.find(num, stuArr);System.out.println(是否繼續查找學生信息?是(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(執行更新學員的基本信息操作);adminStu.print(stuArr);/ 輸出所有學生信息System.out.println(請輸入學生的學號:);int num = in.nex
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 西安理工大學《新時代高校勞動教育通論》2023-2024學年第二學期期末試卷
- 南京理工大學《乒乓球教學》2023-2024學年第二學期期末試卷
- 吉首大學張家界學院《聲樂一》2023-2024學年第二學期期末試卷
- 滁州職業技術學院《民間美術圖形創新設計》2023-2024學年第二學期期末試卷
- 桂林醫學院《軟件設計模式與體系結構(雙語)》2023-2024學年第二學期期末試卷
- 社區服務中心設計
- 小學科學實驗室安全教育
- 2024年水電站計算機監控裝置項目資金籌措計劃書代可行性研究報告
- 相關管理規定制度的教育
- 新生兒肺炎護理
- 吉林市富源石材有限公司三佳子飾面花崗巖及周邊礦區礦山地質環境保護與土地復墾方案
- 2022年上海奉賢經濟發展有限公司招聘筆試題庫及答案解析
- 新教材人教版高中數學必修第二冊全冊教案(教學設計)
- DB23∕T 440-1996 柞蠶生產技術規程
- 藥物溶解與溶出及釋放-精品醫學課件
- 安達信-深圳證券交易所人力資源管理咨詢項目現狀分析報告PPT課件
- 畢業論文行星減速器設計完稿
- 安徽高中畢業生登記表(共7頁)
- 半波偶極子天線地HFSS仿真設計
- 混凝土攪拌車車隊管理制度
- 小學生美術課件-第16課--你會設計郵票嗎|蘇少版-(31張PPT)
評論
0/150
提交評論