Java第一次考試作業
阿新 • • 發佈:2018-09-25
span 包括 是否 判斷 char 3.5 返回 記錄 gen date為字符串類型String,用於存儲操作的時間,由十位字符組成,顯示格式為“2018-09-20”。 變量operatetype為int類型,用於存儲操作賬戶的類型,具體描述為“1”表示存款,“2”表示取款,“3”表示轉賬匯款,“4”表示修改賬戶密碼,“5”表示查詢余額。變量accountpassword為字符串類型String,用於用戶密碼,由六位數字組成。變量accountbalance為整數類型int,用於存儲賬戶余額,缺省為0。變量amount為整數類型int,表示操作流水金額。對每個變量定義get())和set()的方法。定義accountinformation.txt作為賬戶基本信息庫,基本信息包括accountID,accountname,accountpassword, accountbalance,要求事先實現至少存儲五個賬戶的信息,定義 accountlist.txt作為賬戶操作流水信息數據庫,操作流水信息包括(accountID,accountname,operatedate,operatetype, amount)。其功能要求為該程序模擬ATM的功能設計,當用戶插卡後顯示,輸入密碼界面,用戶輸入正確密碼(用戶輸入錯誤密碼,則提示該卡已被鎖定,無法操作),則彈出選擇界面:存款、取款、轉賬匯款、修改密碼、查詢余額。
這次考試感覺自己充分的意識到自己的不足,對於Java沒有系統的理解,敲程方面也有很大問題,本次程序題目為ATM機的賬戶記錄Account有賬戶的唯一性標識,用戶的姓名,操作日期(Date),操作類型,賬戶密碼,當前的余額。定義Account類,其中包括七個私有變量(accountID,accountname,operatedate,operatetype,accountpassword, accountbalance)。各成員的含義如下:變量accountID為字符串類型String,用於存儲學生的用戶賬號(由八位數字組成)。變量accountname為字符串類型String,用於存儲賬戶的名稱。變量operate
個人感覺通過此次編程自己又學到了很多,比如界面輸出語句的具體使用方法,Java中輸入輸出b語句的使用,Java中判斷所輸入數據是否為正整數,感覺自己假期的學習還是很的不足,差了很多,深刻的認識到了自己的不足,也打算在接下來的時間裏好好學習代碼,就像建民歐巴說的這次的成績並不是很重要,重要的是通過這次自己學到了什麽,認識到自己有哪些不足,並從這次的錯誤中看到自己的不足,並學會他,搞定他,最終能夠成功的運用它,畢竟自己腦袋裏的東西最重要,熟練應用自己的知識也很重要,我覺得通過這次自己也真的意識到到底差在哪裏和別人的差距在哪裏,自己又有哪些不足的,最後,既然自己選擇了這個專業,那就一定要對的起自己的選擇,也相信自己會在這半年的學習中讓自己更加的優秀
package moniATM; import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncondingException; import java.nio.charset.Charset; import java.util.scanner; public class Account { private String accountID; private String accountname; private String operatedate; private int operatetype; private String accountpassword; private int accountbalance; private int amount; public Account() { } public Account(String IDcard, String Name, String Adress, String password, int balance) { this.accountID = accountID; this.accountname = accountname; this.operatedate = operatedate; this.operatetype=operatetype; this.accountpassword = accountpassword; this.accountbalance = accountbalance; } public void setaccountname(String acccountname) { this.accountname = accountname; } public void setsetaccountID() { this.accountID = accountID; } public void setoperatedate(String operatedate) { this.operatedate = operatedate; } public void setoperatetype(int operatetype) { this.operatetype =operatetype; } public void setaccountpassword(String accountpassword) { this.accountpassword = accountpassword; } public void setaccountbalance(int accountbalance) { this.accountbalance = accountbalance; } public void setamount(int amount) { this.amount = amount; } public String getaccountID() { return accountID; } public String getaccountname() { return accountname; } public String getoperatedate() { return operatedate; } public int getoperatetype() { return operatetype; } public String getaccountpassword() { return accountpassword; } public int getaccountbalance() { return accountbalance; } public int getamount() { return amount; } public void setAccount() { // TODO Auto-generated method stub } }
package moniATM; import java.io.FileWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncondingException; import java.util.Scanner; import com.sun.codemodel.internal.writer.FileCodeWriter; public class AccountManager { public Object accountID; public Object accountpassword; public class Main { private static final String NULL = null; private Object system; public void main(String[] args) throws UnsupportedEncodingException { char choise; int i = 0; boolean flag;//判斷標識 Scanner sc = new Scanner(System.in); Account[] array = new Account[100]; public void setList(int i,ArrayList<Account> ac) { try { Account a=ac.get(i); } catch(Exception e) { System.out.println("文件寫入失敗"); } } for (int n = 0; n < 100; n++) { array[n] = new Account("asd", "asd", "asd", "asd", 1); } do { System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀 |"); System.out.println("|**********************************************|"); System.out.println("| 請輸入您的賬號 |"); System.out.println("|**********************************************|"); System.out.println(""); boolean isNULL; if(isNULL) { System.out.println("|**********************************************|"); System.out.println("| 該卡不是工商卡 |"); System.out.println("|**********************************************|"); } else { System.out.println("********************************************"); System.out.println(" 歡迎使用中國工商銀行自助櫃員系統 "); System.out.println("********************************************"); System.out.println(" 請輸入您的密碼 "); System.out.println("********************************************"); } public void setInformation(ArrayList<Account> ac)//寫入信息 { try { int i=0; FileWriter fw=new FileWriter("AccountInformation"); PrintWriter pw=new PrintWriter(fw); for(i=0;i<ac.size();i++) { pw.println(((Object) ac.get(i)).getAccountID()+" "+((Object) ac.get(i)).getAccontpassword()+" "+ ac.get(i).getAccountname()+" "+ac.get(i).getAccountbalance()); } pw.flush(); pw.close(); fw.close(); } { System.out.println("|**********************************************|"); System.out.println("| 密碼輸入錯誤,請重新輸入 |"); System.out.println("|**********************************************|"); counter++; }while(counter<3); Lock_Sys(); if(isRight(accountID,accountpassword)) { System.out.println("|**********************************************|"); System.out.println("| 1.存款; |"); System.out.println("| 2.取款; |"); System.out.println("| 3.轉賬匯款: |"); System.out.println("| 4.修改密碼 |"); System.out.println("| 5.查詢 余額 |"); System.out.println("|**********************************************|"); } switch (choise) { case ‘1‘: System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("| 請輸入存款金額 |"); System.out.println("|**********************************************|"); if(isNULL) { System.out.println("|**********************************************|"); System.out.println("| 輸入金額有誤,返回取款頁面 |"); } else { System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("|**********************************************|"); System.out.println("| 存款成功 現金額為 |"); }; case ‘2‘:{ int amount; System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("|**********************************************|"); System.out.println("| 當前賬戶每日可支取2萬元 |"); System.out.println("| 1.100元 |"); System.out.println("| 2.200元 |"); System.out.println("| 3.500元 |"); System.out.println("| 4.1000元 |"); System.out.println("| 5.2000元 |"); System.out.println("| 6.5000元 |"); System.out.println("| 7.其他金額 |"); System.out.println("| 8.退卡 |"); System.out.println("| 9.退回 |"); System.out.println("|**********************************************|"); int t; t = sc.nextInt(); switch (t) { case 1:amount = 100;break; case 2:amount = 200;break; case 3:amount = 500;break; case 4:amount = 1000;break; case 5:amount = 2000;break; case 6:amount = 5000;break; } if(amount>array[0].getaccountbalance()) System.out.println("余額不足"); } case ‘3‘: System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("|**********************************************|"); System.out.println("| 請輸入轉賬金額 |"); System.out.println("|**********************************************|"); array[0].setamount(sc.nextInt()); Account a=new Account(); Account b=new Account(); Scanner input=new Scanner(System.in); String z="",x=""; int t=0,m=0,f1=0; while(f1==0) { face(i,6,ac); z=input.next(); if((t=id(z,ac))>=0)//判斷 { try { face(i,7,ac); m=input.nextInt(); if(m<=0)throw new Exception(); } catch(Exception e) { face(i,13,ac); f1=1; continue; } if(f1==0)//輸入正確 開始轉賬 { a=ac.get(i); b=ac.get(t); a.setAmount(-m); b.setAmount(m); ac.set(i, a); face(i,t,1,ac); x=input.next(); if(x.equals("Y")==true) { a.setOperatedate(); a.setOperatetype(3); b.setOperatedate(); b.setOperatetype(3); if(ac.get(i).getAccountbalance()>=m) { a.setAccountbalance(a.getAccountbalance()-m); ac.set(i, a); setList(i, ac); b.setAccountbalance(b.getAccountbalance()+m); ac.set(t, b); setList(t, ac); setInformation(ac); face(i,t,2,ac); break; } else { face(i,19,ac); break; } } else if(x.equals("N")==true) { break; } else { face(i,20,ac); } } } } } case ‘4‘: System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("|**********************************************|"); System.out.println("| 請輸入當前密碼 |"); System.out.println("| 請輸入修改密碼 |"); System.out.println("| 請輸入確認密碼 |"); public int id(String accountID,ArrayList<Account> ac) { int i=0,t=0; if(accountID.length()!=8) { return -2; } for(t=0;t<accountID.length();t++) { if(accountID.charAt(t)<‘0‘||accountID.charAt(t)>‘9‘) { return -2; } } for(i=0;i<ac.size();i++) { if(ac.get(i).getAccountID().equals(accountID)==true) { return i; } } return -1; } case ‘5‘: System.out.println("|**********************************************|"); System.out.println("| 歡迎使用中國工商銀行自助櫃員系統 |"); System.out.println("|**********************************************|"); System.out.println("| 當前賬戶余額為: "+array[0].getaccountbalance()+" 元 |"); System.out.println("| 賬戶清單信息為 |"); System.out.println("| 1.操作日期 操作類型 操作金額 |"); public int login(int i,String accountpassword,ArrayList<Account> ac) { int t=0; if(accountpassword.length()!=6) { return -1; } for(t=0;t<accountpassword.length();t++) { if(accountpassword.charAt(t)<‘0‘||accountpassword.charAt(t)>‘9‘) { return -1; } } if(ac.get(i).getAccontpassword().equals(accountpassword)==true) { return 1; } else { return -1; } }
Java第一次考試作業