考后反思

// 信1905-1班 20194113 赵浩博
package ceshi;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
class Account {
private String accountID;
private String accountname;
private String operatedate;
private int operatetype;
private String accountpassword;
private int accountbalance;
private int amount;
Account(){accountbalance=0;}
Account(String ID,String n,String o,int t){
accountID=ID;
accountname=n;
accountpassword=o;
accountbalance=t;
}
public void setaccountID(String ID) {
accountID=ID;
}
public void setaccountname(String n) {
accountname=n;
}
public void setoperatedate(String o) {
operatedate=o;
}
public void setoperatetype(int t) {
operatetype=t;
}
public void setaccountpassword(String p) {
accountpassword=p;
}
public void setaccountbalance(int b) {
accountbalance=b;
}
public void setamount(int m) {
amount=m;
}
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 class AccountManager extends Account{
Account ac=new Account();
Account[] ab=new Account[10];
int n=0;
public void Out()throws IOException{
int i=0;
File p=new File("d:/accountinformation.txt");
FileReader ad=new FileReader(p);
Scanner sc=new Scanner(ad);
for(i=0;i<5;i++) {
ab[i]=new Account();
ab[i].setaccountID(sc.next());
ab[i].setaccountname(sc.next());
ab[i].setaccountpassword(sc.next());
ab[i].setaccountbalance(sc.nextInt());
}
sc.close();
ad.close();
n=5;
}
public boolean enterNumber() {
boolean c=false;
Scanner sc=new Scanner(System.in);
String ID;
int o=0,j;
do {
System.out.println("*******************************************************");
System.out.println(" 欢迎使用中国工商银行自动柜员系统");
System.out.println("*******************************************************");
System.out.println(" 请输入您的账号:");
ID=sc.next();
System.out.println("*******************************************************");
if(ID.length()!=8) {System.out.println("该卡不是工行卡");}
for(j=0;j<n;j++)
{
ac=ab[j];
if(ID.equals(ac.getaccountID()))break;
else o++;
}
if(o==n) {System.out.println("该账号不存在");c=true;}
}while(c);
return c;
}
public boolean enterPassword() {
Scanner sc=new Scanner(System.in);
String pass;
boolean b=false;
int c=0;
do {
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println(" 请输入您的密码:");
pass=sc.next();
System.out.println("********************************************************");
if(!pass.equals(ac.getaccountpassword())||pass.length()!=6) {System.out.println("密码录入错误");c=c+1;}
if(c==3) {System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");}
if(pass.equals(ac.getaccountpassword())){b=true;break;}
}while(c<3);
return b;
}
public boolean doposit() throws IOException{
Scanner sc=new Scanner(System.in);
boolean a=false;
boolean b=false;
String c;
int money;
do {
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("请输入存款金额:");
money=sc.nextInt();
System.out.println("********************************************************");
if(money<=0) {System.out.println("输入金额有误");a=true;}
else {
ac.setaccountbalance(ac.getaccountbalance()+money);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println(" 当前账户存款操作成功。");
System.out.println(" 当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(money);
ac.setoperatetype(1);
File p=new File("d:/accountinformation.txt");
FileWriter ad=new FileWriter(p);
BufferedWriter am=new BufferedWriter(ad);
for(int i=0;i<5;i++) {
am.write(ab[i].getaccountID());
am.write(" ");
am.write(ab[i].getaccountname());
am.write(" ");
am.write(ab[i].getaccountpassword());
am.write(" ");
String s=Integer.toString(ab[i].getaccountbalance());
am.write(s);
am.newLine();
}
am.close();
ad.close();
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("yyyy-MM-dd");
String s=ft.format(dNow);
ac.setoperatedate(s);
File q=new File("d:/accountlist.txt");
FileWriter al=new FileWriter(q,true);
BufferedWriter an=new BufferedWriter(al);
an.write(ac.getaccountID());
an.write(" ");
an.write(ac.getaccountname());
an.write(" ");
an.write(ac.getoperatedate());
an.write(" ");
an.write(Integer.toString(ac.getoperatetype()));
an.write(" ");
an.write(Integer.toString(ac.getamount()));
an.newLine();
an.close();
al.close();
break;
}
}while(a);
System.out.println("如果退出柜员机请输入“q”,不退出按除“q的任意键");
c=sc.next();
if(c.equals("q"))b=true;
return b;
}
public boolean withdrawal()throws IOException{
boolean c=false;
Scanner sc=new Scanner(System.in);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
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("********************************************************");
int n;
n=sc.nextInt();
int t;
for(;;)
{
boolean v=false;
switch(n) {
case 1:if(ac.getaccountbalance()<100) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-100);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作100元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(100);
v=true;
}
break;
case 2:if(ac.getaccountbalance()<500) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-500);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作500元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(500);
v=true;
}
break;
case 3:if(ac.getaccountbalance()<1000) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-1000);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作1000元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(1000);
v=true;
}
break;
case 4:if(ac.getaccountbalance()<1500) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-1500);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作1500元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(1500);
v=true;
}
break;
case 5:if(ac.getaccountbalance()<2000) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-2000);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作2000元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(2000);
v=true;
}
break;
case 6:if(ac.getaccountbalance()<5000) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-5000);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作5000元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(5000);
v=true;
}
break;
case 7:System.out.println("请输入金额:");
t=sc.nextInt();
if(ac.getaccountbalance()<t) {System.out.println("余额不足");}
else {
ac.setaccountbalance(ac.getaccountbalance()-t);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户取款操作"+t+"元成功");
System.out.println("当前账户余额为:"+ac.getaccountbalance());
System.out.println("********************************************************");
ac.setamount(t);
v=true;
}
break;
case 8:c=true;break;
case 9:break;
}
if(n==9||n==8)break;
if(v) {
ac.setoperatetype(2);
File p=new File("d:/accountinformation.txt");
FileWriter ad=new FileWriter(p);
BufferedWriter am=new BufferedWriter(ad);
for(int i=0;i<5;i++) {
am.write(ab[i].getaccountID());
am.write(" ");
am.write(ab[i].getaccountname());
am.write(" ");
am.write(ab[i].getaccountpassword());
am.write(" ");
String s=Integer.toString(ab[i].getaccountbalance());
am.write(s);
am.newLine();
}
am.close();
ad.close();
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("yyyy-MM-dd");
String s=ft.format(dNow);
ac.setoperatedate(s);
File q=new File("d:/accountlist.txt");
FileWriter al=new FileWriter(q,true);
BufferedWriter an=new BufferedWriter(al);
an.write(ac.getaccountID());
an.write(" ");
an.write(ac.getaccountname());
an.write(" ");
an.write(ac.getoperatedate());
an.write(" ");
an.write(Integer.toString(ac.getoperatetype()));
an.write(" ");
an.write(Integer.toString(ac.getamount()));
an.newLine();
an.close();
al.close();
}
n=sc.nextInt();
}
return c;
}
public boolean transfer()throws IOException {
boolean b=false;
String a;
int c,o=0;
Scanner sc=new Scanner(System.in);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("请输入转账账户:");
a=sc.next();
System.out.println("********************************************************");
Account v=new Account();
for(int j=0;j<n;j++)
{
v=ab[j];
if(a.equals(v.getaccountID()))break;
else o++;
}
if(o==5) {System.out.println("该用户不存在");}
else {
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("请输入转账金额:");
c=sc.nextInt();
System.out.println("********************************************************");
if(c>ac.getaccountbalance())System.out.println("账户余额不足");
else {
char[] m=v.getaccountname().toCharArray();
m[0]='*';
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.print("请确认是否向");
for(int k=0;k<m.length;k++)
System.out.print(m[k]);
System.out.println("转账"+c+"元。");
System.out.println("不确认转账请输入“N”,确认转账输入“Y”,");
String l=sc.next();
if(l.equals("N")) {}
else if(l.equals("Y")){
ac.setaccountbalance(ac.getaccountbalance()-c);
v.setaccountbalance(v.getaccountbalance()+c);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户向");
for(int k=0;k<m.length;k++)
System.out.print(m[k]);
System.out.println("成功转账");
System.out.println("当前账户余额为:"+ac.getaccountbalance()+"元");
System.out.println("********************************************************");
ac.setamount(c);
ac.setoperatetype(3);
File p=new File("d:/accountinformation.txt");
FileWriter ad=new FileWriter(p);
BufferedWriter am=new BufferedWriter(ad);
for(int i=0;i<5;i++) {
am.write(ab[i].getaccountID());
am.write(" ");
am.write(ab[i].getaccountname());
am.write(" ");
am.write(ab[i].getaccountpassword());
am.write(" ");
String s=Integer.toString(ab[i].getaccountbalance());
am.write(s);
am.newLine();
}
am.close();
ad.close();
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("yyyy-MM-dd");
String s=ft.format(dNow);
ac.setoperatedate(s);
File q=new File("d:/accountlist.txt");
FileWriter al=new FileWriter(q,true);
BufferedWriter an=new BufferedWriter(al);
an.write(ac.getaccountID());
an.write(" ");
an.write(ac.getaccountname());
an.write(" ");
an.write(ac.getoperatedate());
an.write(" ");
an.write(Integer.toString(ac.getoperatetype()));
an.write(" ");
an.write(Integer.toString(ac.getamount()));
an.newLine();
an.close();
al.close();
}
}
}
System.out.println("如果退出柜员机请输入“q”,不退出按除“q的任意键");
a=sc.next();
if(a.equals("q"))b=true;
return b;
}
public boolean update() throws IOException{
String b,d,v;
boolean c=false;
String m;
Scanner sc=new Scanner(System.in);
for(;;) {
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("请输入当前密码");
b=sc.next();
System.out.println("请输入修改密码");
d=sc.next();
System.out.println("请输入确认密码");
v=sc.next();
System.out.println("********************************************************");

if(b.equals(ac.getaccountpassword())) {
if(d.equals(v)) {
ac.setaccountpassword(d);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户密码修改成功");
System.out.println("********************************************************");
ac.setamount(0);
ac.setoperatetype(4);
File p=new File("d:/accountinformation.txt");
FileWriter ad=new FileWriter(p);
BufferedWriter am=new BufferedWriter(ad);
for(int i=0;i<5;i++) {
am.write(ab[i].getaccountID());
am.write(" ");
am.write(ab[i].getaccountname());
am.write(" ");
am.write(ab[i].getaccountpassword());
am.write(" ");
String s=Integer.toString(ab[i].getaccountbalance());
am.write(s);
am.newLine();
}
am.close();
ad.close();
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("yyyy-MM-dd");
String s=ft.format(dNow);
ac.setoperatedate(s);
File q=new File("d:/accountlist.txt");
FileWriter al=new FileWriter(q,true);
BufferedWriter an=new BufferedWriter(al);
an.write(ac.getaccountID());
an.write(" ");
an.write(ac.getaccountname());
an.write(" ");
an.write(ac.getoperatedate());
an.write(" ");
an.write(Integer.toString(ac.getoperatetype()));
an.write(" ");
an.write(Integer.toString(ac.getamount()));
an.newLine();
an.close();
al.close();
break;
}
else System.out.println("修改密码与确认密码不一致");
}
else System.out.println("当前密码录入错误");
}
System.out.println("如果退出柜员机请输入“q”,不退出按除“q的任意键");
m=sc.next();
if(m.equals("q"))c=true;
return c;
}
public boolean inqury() throws IOException{
boolean b=false;
String c;
int i=1;
Account sv=new Account();
Scanner sc=new Scanner(System.in);
System.out.println("********************************************************");
System.out.println(" 欢迎"+ac.getaccountname()+"使用中国工商银行自助柜员系统");
System.out.println("********************************************************");
System.out.println("当前账户余额为"+ac.getaccountbalance());
System.out.println("账户清单信息为:");
File p=new File("d:/accountlist.txt");
FileReader ad=new FileReader(p);
Scanner a=new Scanner(ad);
while(a.hasNext()) {
sv.setaccountID(a.next());sv.setaccountname(a.next());
sv.setoperatedate(a.next());sv.setoperatetype(a.nextInt());
sv.setamount(a.nextInt());
if(sv.getaccountID().equals(ac.getaccountID())) {
System.out.print(i+"、"+sv.getoperatedate());
if(sv.getoperatetype()==1)System.out.print(" 存款 ");
else if(sv.getoperatetype()==2)System.out.print(" 取款 ");
else if(sv.getoperatetype()==3)System.out.print(" 转款 ");
else if(sv.getoperatetype()==4)System.out.print(" 修改密码 ");
System.out.println(sv.getamount());
i++;
}
}
a.close();
ad.close();
System.out.println("********************************************************");
System.out.println("如果退出柜员机请输入“q”,不退出按除“q的任意键");
c=sc.next();
if(c.equals("q"))b=true;
return b;
}
public static void main(String[] args) {
AccountManager b=new AccountManager();
Scanner sc=new Scanner(System.in);
try{b.Out();
int n;
do {
boolean a,c,d=false;
a=b.enterNumber();
c=b.enterPassword();
if(!c)System.exit(0);
for(;;) {
System.out.println("*********************************************************");
System.out.println(" 欢迎"+b.ac.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("********************************************************");
n=sc.nextInt();
if(n==1) {
d=b.doposit();
if(d)break;
}
else if(n==2) {
d=b.withdrawal();
if(d)break;
}
else if(n==3){
d=b.transfer();
if(d)break;
}
else if(n==4) {
d=b.update();
if(d)break;
}
else if(n==5) {
d=b.inqury();
if(d)break;
}
}
}while(true);}catch(Exception e) {}
}
}

 

 

 

 

 

今天进行了java的入学测试,此次测试题目是ATM取款机的编程,经过一下午的编程,没有完成此次的测试,以此,我反思了自己没有完成此次测试的原因。

最根本的原因是我对java学习的还不够透彻以及没有对题目进行分析构思,只学到了最基本的一些操作,许多的java语法不熟练。并且对此次测试中涉及的知识点没有有透彻的理解,也没有熟练地掌握,本次测验中,使用到java的字符串操作、文件操作、数组知识、异常机制等内容。对于java的字符串应用方面,我掌握的不够完全,会使用String来初始化字符,但对于字符串的方法不了解,只对于String的equal方法熟练些,而对于Sting的转化字符数组的方法不了解,对基础的String的length方法都未想到使用。所以对于字符串方法的不熟练和不了解导致我在进行程序编写时加大了程序的难度。而在测试过程中,需要用到文件的操作,但因为对文件流中的字节流、字符流、过滤流等的语法都不熟练,导致对于需要使用文件流的部分总是很彷徨,而通过搜到了关于文件流的知识之后,应用到程序之中总会出现错误,并且因为对java的异常机制不够了解,所以在使用创建文件,使用文件时总是会发生错误。文件流需要使用Exception类中的throws、try……catch等来进行规范,但我对这些的不熟练导致我在进行调试试总会不能运行程序,导致花费较长时间来进行这方面的尝试,而最后还是未能成功将文件操作应用到程序的编程中,白浪费了时间。除此之外,对于条件控制的使用还不是太过熟练,编写中对于条件套条件时总会弄混一些语句。最后就是自己的实践还是太少,对题目没有一个完整的构思,没有分析出题目所用的内容,对于如何来编写这一个程序脑子里都是混乱的,思路不清晰。没有耐下心来去解析题目进行构思。心急撩撩的就开始进行编程。导致编写过程中不了解自己究竟要如何做、怎样来实现功能,对每一部分要使用什么语法和知识没有概念。

其次是自己对于编程的习惯也不规范。首先是,没有将程序进行分层次,导致代码一堆不方便进行检查。其次在编程过程中,对于一个类总会在编程到后面部分时,对自己所写的前面方法忘记,导致频繁需要重新整理思路来进行编程。并且没有养成加注释和标准命名方法的好习惯。不知道对自己写好的方法进行注释,需要花费时间一个个的去翻找之前写的方法。对于变量的命名总是偷懒的使用a,b,c,d等来进行标识,没有按照java标识符的命名规则来进行,导致在命名变量时会发生变量名重复的错误。除此之外就是没有逐步来对代码进行调试,没有进行一部分一部分的调试,直接就是一堆代码放在一起调试,最后出现了错误,却找不到错误出现了那个方法里,而且错误会分布在不同方法中,需要将所有方法的错误都进行改正后才能运行程序,最后只就能不断进行调试,花费大量时间来寻找错误,不能一部分一部分的来进行修改。

总之,经过此次测验,我发现自己的许多不足,对java知识的不了解,对java语法的不熟练。坏的编程习惯,没有养好编程的好习惯。因而,在之后的学习中,我要对自己进行严格要求。首先,需要要进行java的学习,去学习文件的操作,了解文件的字节流、字符流、缓冲流、处理流等,认真的去练习,熟练地掌握这些知识,除此之外,对于Java的其他语法也要进行不断实践使用。熟练地去掌握这些基本的语法知识。不在基础语法上出现不会的情况。还要不断地去做一些有难度的题,提高自己对难题的解决能力,不断地实践练习提高自己的编程能力。其次是要学会思考,做一道题时,要学会去思考如何去做这样一道题,分析它涉及的是哪方面知识,使用什么结构来做。在脑海里进行构思,有一张解决问题的蓝图。不盲目的进行去做题,不盲目的进行编写。最后,我要改变自己现在的编程习惯,养成良好的编程习惯,按照命名规则进行命名、学会加注释,学会使用空格等来增加程序的可读性等。

原文地址:https://www.cnblogs.com/haobox/p/13715686.html