Java课堂测试01及感想
? 上周進行了Java的開學第一次測驗,按要求做一個模擬ATM機功能的程序,實現存取款、轉賬匯款、修改密碼、查詢余額的操作。這次測驗和假期的試題最大的不同還是把數組存儲改成的文件存儲,在聽到老師說要用文件的時候,還是有種悔不當初的感覺的,假期里找的教程是有教文件的,當時想著假期給的試題僅要求數組,就偷了懶。這次測驗的時候,看了一下文件的教程,不是怎么清楚怎么像題目那樣使用文件,便放棄了這一部分,還是用的數組。這次測驗還發現了自己的很多問題,特別是一些習慣上的問題。以前寫的都是幾十行的小程序,簡單看下題目就知道該怎么做,而這次的測驗卻沒那么小了。拿到題目的時候老師有叫過我們先構思,不要立刻動手,我看了題目想了一會兒,并沒有很清楚的思路,只有一個模糊的想法,就開始動手,寫到執行文件時就不太記得一開始的想法,寫一會就看一會題目,翻翻剛寫的代碼,浪費了很多時間。寫著寫著就發現少了一些東西,又去前面加,后面都亂了。測試的時間從兩個小時延長到兩個半小時再到三個小時,可以說是很足了,但是我還是只實現了前面兩個功能,也是和思路的混亂有關,當然更主要的是能力不足,暑假的學習太過應付了事,以后還是要努力才行,不能再貪玩了。
Account.java
1 public class Account { 2 3 private String accountID; //賬號 4 private String accountname; //名稱 5 private String operatedate; //操作時間 6 private int operatetype; 7 private String accountpassword; //密碼 8 private int accountbalance; //賬戶余額 9 private int amount; //流水金額 10 11 public String getAccountID() { 12 return accountID; 13 } 14 public void setAccountID(String accountID) { 15 this.accountID = accountID; 16 } 17 public String getAccountname() { 18 return accountname; 19 } 20 public void setAccountname(String accountname) { 21 this.accountname = accountname; 22 } 23 public String getOperatedate() { 24 return operatedate; 25 } 26 public void setOperatedate(String operatedate) { 27 this.operatedate = operatedate; 28 } 29 public int getOperatetype() { 30 return operatetype; 31 } 32 public void setOperatetype(int operatetype) { 33 this.operatetype = operatetype; 34 } 35 public String getAccountpassword() { 36 return accountpassword; 37 } 38 public void setAccountpassword(String accountpassword) { 39 this.accountpassword = accountpassword; 40 } 41 public int getAccountbalance() { 42 return accountbalance; 43 } 44 public void setAccountbalance(int accountbalance) { 45 this.accountbalance = accountbalance; 46 } 47 public int getAmount() { 48 return amount; 49 } 50 public void setAmount(int amount) { 51 this.amount = amount; 52 } 53 54 Account( String accountID,String accountname,String accountpassword){ 55 this.accountID = accountID; 56 this.accountname = accountname; 57 this.accountpassword = accountpassword; 58 accountbalance = 0; 59 } 60 61 }AccountManager.java
import java.util.Scanner;public class AccountManager {Scanner in = new Scanner( System.in );Account[] acc = new Account[1000];int i=5;int j,k;int temp = 0;public void InterfaceAccount(){acc[0] = new Account("20173445","劉**","123456");acc[1] = new Account("20170001" ,"張三","387592");acc[2] = new Account("20170002","李四","035432");acc[3] = new Account("20170004","王五","830294");acc[4] = new Account("20170005","趙六","208493");temp=0;String accountID;System.out.println("**************************************************");System.out.println(" 歡迎使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.print(" 請輸入您的賬號:");accountID = in.next();if( accountID.length() != 8 ){System.out.println("**************************************************");System.out.println("該卡不是工行賬號");InterfaceAccount();}else{for( j=0; (j<i) && (temp==0); j++ ){if( acc[j].getAccountID().equals( accountID ))temp = 1;}if(temp==0){System.out.println("**************************************************");System.out.println("該賬號不存在");InterfaceAccount();}else{j--;InterfacePassword();}}}public void InterfacePassword(){String accountpassword;int h=3;System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");while((h--)>0){System.out.print(" 請輸入您的密碼:");accountpassword = in.next();if( acc[j].getAccountpassword().equals( accountpassword)){InterfaceMain();}else{System.out.println("**************************************************");System.out.println("密碼輸入錯誤");if( h==0){System.out.println("**************************************************");System.out.println("該賬號三次錄入密碼錯誤,該卡已被系統沒收,請與工行及時聯系處理");InterfaceAccount();}}}}public void InterfaceMain(){int operatetype;System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");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("**************************************************");operatetype = in.nextInt();acc[j].setOperatetype(operatetype);switch(operatetype){case 1:deposit();break;case 2:withdraw();break;}}public void deposit(){ //存款int amount;System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.println(" 請輸入存款金額:");amount = in.nextInt();String s = String.valueOf(amount);if( s.equals("q"))InterfaceAccount();else{if( amount <= 0 ){System.out.println("輸入金額有誤");withdraw();}else{System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.println(" 當前賬戶存款操作成功");acc[j].setAccountbalance( acc[j].getAccountbalance()+amount );System.out.println(" 當前賬戶余額為:"+acc[j].getAccountbalance()+"元");System.out.println("**************************************************");s = in.next();if( s.equals("q"))InterfaceAccount();}}}public void withdraw(){ //取款int amount = 0;System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.println(" 當前賬戶每日可以支取2萬元");System.out.println(" 1、 100元");System.out.println(" 2、 500元");System.out.println(" 3、 1000元");System.out.println(" 4、 1500元");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("**************************************************");temp = in.nextInt();switch(temp){case 1:amount=100;break;case 2:amount=500;break;case 3:amount=1000;break;case 4:amount=1500;break;case 5:amount=2000;break;case 6:amount=5000;break;case 7:{System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.println(" 請輸入取款金額");amount = in.nextInt();break;}default:break;}if( amount > acc[j].getAccountbalance() )System.out.println("賬戶余額不足");else{System.out.println("**************************************************");System.out.println(" 歡迎"+acc[j].getAccountname()+"使用中國工商銀行自動柜員系統");System.out.println("**************************************************");System.out.println("當前賬戶取款操作"+amount+"元成功");acc[j].setAccountbalance( acc[j].getAccountbalance()+amount);System.out.println("當前賬戶余額為:"+acc[j].getAccountbalance()+"元");System.out.println("**************************************************");}if( temp == 8 )InterfaceAccount();if(temp==9)InterfaceMain();}}ATM.java
/** 信1705-1* 20173445* 劉*/ public class ATM {public static void main( String[] args){AccountManager manager = new AccountManager();manager.InterfaceAccount();} }轉載于:https://www.cnblogs.com/gothic-death/p/9697332.html
總結
以上是生活随笔為你收集整理的Java课堂测试01及感想的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 爬虫基本原理讲解
- 下一篇: Flutter 15: 图解 ListV