一、java测试题目(ATM自助取款机系统)
package ATM; 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 void setaccountID(String accountID1) { accountID=accountID1; } public String getaccountID() { return accountID; } public void setaccountname(String accountname1) { accountname=accountname1; } public String getaccountname() { return accountname; } public void setoperatedate(String operatedate1) { operatedate=operatedate1; } public String getoperatedate() { return operatedate; } public void setoperatetype(int operatetype1) { operatetype=operatetype1; } public int getoperatetype() { return operatetype; } public void setaccountpassword(String accountpassword1) { accountpassword=accountpassword1; } public String getaccountpassword() { return accountpassword; } public void setaccountbalance(int accountbalance1) { accountbalance=accountbalance1; } public int getaccountbalance() { return accountbalance; } public void setamount(int amount1) { amount=amount1; } public int getamount() { return amount; } public Account(String accountID1,String accountname1,String accountpassword1,int accountbalance1) { accountID=accountID1; accountname=accountname1; accountpassword=accountpassword1; accountbalance=accountbalance1; } public Account() {} }
package ATM; import java.util.Scanner; public class AccountManager1 { private static Account[] acc=new Account[5]; private static int mf=-1; private static int sf=-1; public AccountManager1() { for(int i=0;i<5;i++) { acc[i]=new Account(); } acc[0]=new Account("20194021","marongrong","000001",1000); acc[1]=new Account("20190002","zhanghong","000002",2000); acc[2]=new Account("20190003","wanggang","000003",3000); acc[3]=new Account("20190004","sunli","000004",4000); acc[4]=new Account("20190005","zhaoqiang","000005",5000); } //打印出主界面 public static void show1() { System.out.println("*****************************************"); System.out.println(" 欢迎使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入您的账号: "); System.out.println("*****************************************"); } public static void InputID() { int flag=0; Scanner con=new Scanner(System.in); String accountid=con.next(); for(int i=0;i<5;i++) { if(accountid.equals(acc[i].getaccountID())) { flag=1; mf=i; break; } } if(flag==0) System.out.println("该卡不是工行卡!"); if(flag==1) show2(); } //打印出输入密码界面 public static void show2() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入您的密码: "); System.out.println("*****************************************"); } public static void Inputpassword() { int m=0; int f=2; Scanner con=new Scanner(System.in); do { String accountpass=con.next(); if(accountpass.compareTo(acc[mf].getaccountpassword())==0) { f=1; } if(f==2) {System.out.println("密码录入错误!");show2();} if(f==1) {System.out.println("密码输入成功!");show3();break;} m++; }while(m<3); if(m==3)System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工商及时联系处理"); } //打印出功能界面 public static void show3() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].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("*****************************************"); } //存款 public static void show4() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入存款金额: "); System.out.println("*****************************************"); } public static void show5() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 当前帐户存款成功! "); System.out.println(" 当前帐户余额为:"+acc[mf].getaccountbalance()); System.out.println("*****************************************"); } public static void cunkuan() { Scanner con=new Scanner(System.in); int money=con.nextInt(); if(money!=(int)money) { System.out.println("输入金额有误!"); } else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()+money); show5(); } } //取款 public static void show6() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 当前帐户每日可以支取两万元 "); 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("*****************************************"); } public static void show7() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入取款金额: "); System.out.println("*****************************************"); } public static void show8() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 当前帐户账户款成功! "); System.out.println(" 当前帐户余额为:"+acc[mf].getaccountbalance()); System.out.println("*****************************************"); } public static void qukuan() { Scanner con=new Scanner(System.in); System.out.println("请选择:"); int p=con.nextInt(); if(p==1) {if(acc[mf].getaccountbalance()<100)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-100); show8(); }} else if(p==2) {if(acc[mf].getaccountbalance()<500)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-500); show8(); }} else if(p==3) {if(acc[mf].getaccountbalance()<1000)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-1000); show8(); }} else if(p==4) {if(acc[mf].getaccountbalance()<1500)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-1500); show8(); }} else if(p==5) {if(acc[mf].getaccountbalance()<2000)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-2000); show8(); }} else if(p==6) {if(acc[mf].getaccountbalance()<5000)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-5000); show8(); }} else if(p==7) { show7(); int qu=con.nextInt(); if(acc[mf].getaccountbalance()<qu)System.out.println("账户余额不足"); else { acc[mf].setaccountbalance(acc[mf].getaccountbalance()-qu); show8(); } } else if(p==8) { show1(); InputID(); Inputpassword(); int n; System.out.println("请输入序号:"); n=con.nextInt(); switch(n) { case 1:{ show4(); cunkuan(); show5(); break; } case 2:{ show6(); qukuan(); break; } case 3:{ show9(); break; } case 4:{ xiugaimima();break; } case 5:{ chaxun(); break; } } } else if(p==9) {show3(); System.out.println("请输入序号:"); int n=con.nextInt(); switch(n) { case 1:{ show4(); cunkuan(); show5(); break; } case 2:{ show6(); qukuan(); break; } case 3:{ show9(); break; } case 4:{ xiugaimima();break; } case 5:{ chaxun(); break; } } } } //转账 public static void show9() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入转账账户: "); System.out.println("*****************************************"); } public static void show10() { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请输入转账金额: "); System.out.println("*****************************************"); } public static void zhuazhang1() { int flag=0; Scanner con=new Scanner(System.in); String str=con.next(); for(int i=0;i<5;i++) { if(str.equals(acc[i].getaccountID())) { flag=1; sf=i; break; } } if(flag==0) System.out.println("该账户不存在!"); if(flag==1)show10(); } public static void zhuanzhang2() { Scanner con=new Scanner(System.in); int mo=con.nextInt(); if(acc[sf].getaccountbalance()<mo)System.out.println("账户余额不足!"); else { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 请确认是否向"+acc[sf].getaccountname()+"转账"+mo+"元(Y/N)"); System.out.println("*****************************************"); String a=con.next(); if(a.equals("N")) { show3(); System.out.println("请输入序号:"); int n=con.nextInt(); switch(n) { case 1:{ show4(); cunkuan(); show5(); break; } case 2:{ show6(); qukuan(); break; } case 3:{ show9(); break; } case 4:{ xiugaimima();break; } case 5:{ chaxun(); break; } } } if(a.equals("Y")) { System.out.println("*****************************************"); System.out.println(" 欢迎"+acc[mf].getaccountname()+"使用中国工商银行自动柜员系统 "); System.out.println("*****************************************"); System.out.println(" 当前帐户向"+acc[sf].getaccountname()+"成功转账"+mo+"元"); System.out.println(" 当前帐户余额为:"+(acc[sf].getaccountbalance()-mo)+"元"); System.out.println("*****************************************"); } } } //修改密码 public static void xiugaimima() { Scanner con=new Scanner(System.in); System.out.println("请输入新密码:"); String mima=con.next(); acc[mf].setaccountpassword(mima); System.out.println("修改密码成功!"); } //查询余额 public static void chaxun() { System.out.println("余额为:"+acc[mf].getaccountbalance()); } //输入q返回登录账户界面 public static void tuichu() { Scanner con=new Scanner(System.in); if(con.next().equals("q")) { show1(); InputID(); Inputpassword(); int n; System.out.println("请输入序号:"); n=con.nextInt(); switch(n) { case 1:{ show4(); cunkuan(); show5(); break; } case 2:{ show6(); qukuan(); break; } case 3:{ show9(); break; } case 4:{ xiugaimima();break; } case 5:{ chaxun(); break; } } } } public static void main(String[] args) { Scanner con=new Scanner(System.in); AccountManager1 atm=new AccountManager1(); show1(); InputID(); Inputpassword(); int n; System.out.println("请输入序号:"); n=con.nextInt(); switch(n) { case 1:{ show4(); cunkuan(); tuichu(); break; } case 2:{ show6(); qukuan(); break; } case 3:{ show9(); zhuazhang1(); zhuanzhang2(); tuichu(); break; } case 4:{ xiugaimima(); tuichu(); break; } case 5:{ chaxun(); tuichu(); break; } } } }
:
二、心得体会:
今天的ATM自助取款机系统是老师作为暑假过后,开学的第一次课堂测试,会让学长学姐为我们的结果打分。看到题目的第一眼,感觉很难,不能接受这个难度,因为毕竟在家没有接触过这个难度的题目,这是作为检测我们暑假在家里自主学习的结果,在测试的前几天,自己做过上一届学长学姐做过的题目,感觉也挺难得,但是自己亲自敲上代码运行出来以后,感觉也没有那么大的难度了,但是这套题目不一样的是,在我看来,它远比上一套题目难,这套题目的功能也很多,看到题目的第一眼,便是感觉自己不能在规定时间内完成,实现它的全部功能。老实说,写代码之前,首先自己的心理要有一个架构,要明白自己倒是想要写什么功能,功能是怎么样的实现,这都是我们要考虑在内的,只有心理有了这个架构,才明白自己想要用的函数、方法是什么,才能写出功能得以实现的代码。
在这次测试中,一开始遇到了很多的问题,再加上时间很短,心理便慌了起来,没有思绪去做题,显示完成了一些简单的变量的设置,方法的设置,然后心理也不知道先干什么后干什么,只是胡乱的完成各个功能,没有次序,没有层次,不明白有的功能该如何去有效的实现,在这个过程中,出现了很多的错误,自己的思路一点也不清晰,每写一段代码就要进行检验验证,个个界面的相互转换,心里都不明白,没有思路,但是到了后来随着各个功能的编写,自己心里渐渐有了思路,开始可以实现一些简单的功能,一直到存款功能出现错误,然后不断的改进,一直到测试的最后,也没有改好,这也是扣分的原因所在,也是我写的这个程序需要改进完善的地方。
在这次测试之后,我突然明白,自己在暑假学的东西根本不值一提,和写一个稍微难一点的程序来说,根本不算什么,这次测试也让我对自己有了新的定位,自己在暑假学到的东西只是浅层次的,学到的并不多,但是也有的同学学到的东西远比我多得多得多,他们的付出会在每一次的测试中显现出来,在每一次的测试中有所回报。这是第一次测试,今后还有很多很多次的测试,而我,也会在今后的时间里,完善自己,学习更多的专业知识,坚持锻炼自己的编码能力,尽全力完成每次的测试内容。发现自己的问题,在解决每一个问题中提升自己。