9.22第一次测试总结报告

  在拿到这份试题的时候,就知道它对于我来说时比较难的。在前两天,我听到ATM取款机这个试题时,我就开始想过如何实现这个程序并且也搜索过相关的资料,但是最终并没有动手去编写这一个程序。今天看到这份试题时,依然是毫无头绪。

  

可是还是懂一点基本的东西,于是便开始按照文件中的试题要求开始编写程序。其中题目要求有:1、定义Account类,其中包括七个私有变量(accountID,accountname,operatedate,operatetype,accountpassword, accountbalance,)。各成员的含义如下:

变量accountID为字符串类型String,用于存储学生的用户账号(由八位数字组成)。

变量accountname为字符串类型String,用于存储账户的名称。

变量operatedate为字符串类型String,用于存储操作的时间,由十位字符组成,显示格式为“2018-09-20”。    

变量operatetypeint类型,用于存储操作账户的类型,具体描述为“1”表示存款,“2”表示取款,“3”表示转账汇款,“4”表示修改账户密码,“5”表示查询余额。

变量accountpassword为字符串类型String,用于用户密码,由六位数字组成。

变量accountbalance为整数类型int,用于存储账户余额,缺省为0。

变量amount为整数类型int,表示操作流水金额。

首先便是写一个Account类,将七个数据写入该类中并且写出构造函数与各个数据对应的setget方法。这一部分便花费了我很长的时间,每个数据的长度都比较长,所以花费的时间比较长。

接下来便是开始设计AccountManager主要是设计主方法,在主方法中将ATM的整体流程运行起来。首先第一步便是设计输入账号的页面,在输入账号后要能够和文件中已知的账号信息进行比对,如果不存在该账号信息则提示用户不存在该账号用户,如果存在该账号信息则继续进行下一步。下一步即是输入密码,在这一步要能够对所输入的密码的判定,即所输入的密码和文件中该账户信息的密码进行比对,如果密码不正确则要重新输入密码,如果连续输入三次错误密码,接下来跳转出输入密码的页面回到账号的页面。如果密码输入正确,则继续进行下一步。下一步则是跳转到主页面,这一步要首先打印出主页面的5个功能选项。

然后在程序的运行中采用switch结构,然后输入不同的功能选项能够跳转至不同的方法中以实现相应的功能。从刚开始到这里,我的思路比较清晰,而且也可以编写出相应的程序,可以说一个整体的框架已经构建的很完善。在这一过程中也并没有遇到太棘手的问题,可以说从刚开始到现在进行的很顺利,并且运行主方法也能够正常的进行账号信息的输入与密码的输入,并且可以显示出主页面中不同的功能选项。接下来便是设计各个不同功能对应的方法。因为我刚开始并没有采用文件的方法,而是采用数组的方法存储账户的各种信息。所以在写存款这个方法的时候就遇到了问题,就是方法中账号信息所对应的数组编号无法和主方法中正在运行的所对应的账户信息的数组编号对应上。一直没有解决这个问题,所以在这里耽误了很长的时间。最后马上就要到时间,还是没有想到方法解决这一个问题。迫不得已只能放弃继续编写存款功能方法,而是将存款功能中的那一段程序直接放在主方法的进程中,这样就能够没有数组编号无法对应的问题。当我处理完这个存款这一段后,便开始继续写下一个取款那一段。可是时间到了,就很悲伤。不过也没办法了,只能这样验收了。结果分数刚好不及格,就更悲伤了。回来后仔细想了一下这个问题,应该在定义类后定义一个全局变量,然后在主方法进程中和各个功能方法中的数组编号中使用,这样就可以保证在一个进程中提取的信息的都是同一个人的信息。可是验收的代码并没有采用编写各个功能方法的方式去编写。所以还是要编写各个功能对应的方法去实现这个程序。要能够在主方法中调用各个功能方法去实现相应的功能。其中存款方法就是打印出页面由用户输入存款的金额,然后与余额相加并重新赋值给余额。取款方法就是打印出取款的页面,由用户选择或输入取款的金额,然后判断余额是否有这么多,然后在余额上减去取出的钱数。转账汇款方法就是输入转账的账户,将此账户余额减去相应的钱数,对方账户增加相应的钱数。修改密码方法就是由用户输入新密码并将新密码存入相应的信息中。最后一个查询金额方法就是显示相应账户中余额的多少。

到这里,各个方法均实现,在主方法中调用相应的功能方法即可完成此程序的运行。

代码如下:

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 Account() {
  super();
 }
 public String getAccountID() {
  return accountID;
 }
 public void setAccountID(String accountID) {
  this.accountID=accountID;
 }
 public void setAccountname(String accountname) {
  this.accountname=accountname;
 }
 public String getAccountname() {
  return accountname;
 }
 public String getOperatedate() {
  return operatedate;
 }
 public void setOperatedate(String operatedate) {
  this.operatedate=operatedate;
 }
 public int getOperatetype() {
  return operatetype;
  
 }
 public void setOperatetype(int operatetype) {
  this.operatetype=operatetype;
 }
 public String getAccountpassword() {
  return accountpassword;
 }
 public void setAccountpassword(String accountpassword) {
  this.accountpassword=accountpassword;
 }
 public int getAccountbalance() {
  return accountbalance;
 }
 public void setAccountbalance(int accountbalance) {
  this.accountbalance=accountbalance;
 }
 public int getAmount() {
  return amount;
 }
 public void setAmount(int amount) {
  this.amount=amount;
 }
}
 
 
package ATM;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
 
import java.util.Scanner;
public class AccountManager extends Account{
  //继承父类
    public AccountManager(String accountID,String accountname,String operatedate,int operatetype,String accountpassword,int accountbalance,int amount) {
        super(accountID,accountname,operatedate,operatetype,accountpassword,accountbalance,amount);
    }
    public AccountManager() {
    }
    //全局定义
    static Account a=new Account();
    static Scanner s=new Scanner(System.in);
    //选择
 public static void main(String[] args) {
  // TODO 自动生成的方法存根
  try {
            fileout();
            waterout();
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        try {
            if(loginAccount()&&loginPwd()) {
            Menu();
            String option;
            do {
            option=s.next();
            switch(option) {
            case"1":    handmoney();break;
            case"2":    getmoney();break;
            case"3":    moneygogogo();break;
            case"4":    update();break;
            case"5":    moneyhere();break;
            case "q":              ;break;
            default:    System.out.println("错误,请重新输入! ");
            }}while(!"q".equals(option));
            System.out.println("成功退出系统! ");}
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //读取账户基本信息库
    public static void fileout() throws FileNotFoundException {
        try {
        FileReader fr=new FileReader("D:accountinformation.txt");
        Scanner sc=new Scanner(fr);
        while(sc.hasNext()) {
        a.setAccountID(sc.next());
        a.setAccountname(sc.next());
        a.setAccountpassword(sc.next());
        a.setAccountbalance(sc.nextInt());
        }
        sc.close();
        fr.close();
        } catch (IOException e) {
            System.out.println("文件导出成功 ");
        }
    }
    //读取账户流水信息库
    public static void waterout() throws FileNotFoundException {
        try {
        FileReader fr=new FileReader("D:accountlist.txt");
        Scanner sc=new Scanner(fr);
        while(sc.hasNext()) {
        a.setAccountID(sc.next());
        a.setAccountname(sc.next());
        a.setOperatedate(sc.next());
        a.setOperatetype(sc.nextInt());
        a.setAmount(sc.nextInt());
        }
        sc.close();
        fr.close();
        } catch (IOException e) {
            System.out.println("文件导出成功 ");
        }
    }
    //导入账户基本信息库
    public static void filein() throws IOException {
        int i;
        FileReader fr=new FileReader("D:accountinformation.txt");
        FileWriter fw=new FileWriter("D:accountinformation.txt");
        i=fr.read();
        while(i!=-1) {
            fw.write(i);
            fr.read();
        }
        fr.close();
        fw.close();
    }
    //导入账户基本信息库
    public static void waterin() throws IOException {
        int i;
        FileReader fr=new FileReader("D:accountlist.txt");
        FileWriter fw=new FileWriter("D:accountlist.txt");
        i=fr.read();
        while(i!=-1) {
            fw.write(i);
            fr.read();
        }
        fr.close();
        fw.close();
    }
    //打印菜单
    public static void Menu(){
    StringBuffer s=new StringBuffer(" ");
    s.append(" ************************************************* ");
    s.append("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
    s.append(" ************************************************* ");
    s.append(" 1.存款; ");
    s.append(" 2.取款; ");
    s.append(" 3.转账汇款; ");
    s.append(" 4.修改密码; ");
    s.append(" 5.查询余额; ");
    s.append(" ************************************************* ");
    s.append(" (输入q退出系统) ");
    s.append("请操作 ");
    System.out.println(s);
    }
    //打印登陆账号界面
    public static boolean loginAccount() throws IOException  {
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 请输入您的账号: ");
            String checkAccount = s.next();
            if (checkAccount.equals (a.getAccountID())){
                System.out.println("输入账号成功,系统跳转到输入密码界面 ");
                return true ;
          }else {
                   System.out.println("该账号不存在 ");
                   return false ;
                }
    }
    //打印登陆密码界面
    public static boolean loginPwd() throws IOException {
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        for (int i = 3 ;i>0;i--){
            System.out.println(" 请输入您的密码: ");
            String checkPwd = s.next();
            if (a.getAccountpassword().equals (checkPwd)){
                System.out.println("输入密码成功,系统跳转到主界面! ");
                return true ;
          }else {
                if ( i ==1 ){
                    System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理 ");
                   return false ;
                }
                System.out.println("密码录入错误!今日剩余次数:"+ (i-1));
           }
        }
        return false;
  
    }
    //存款
    private static void handmoney() {
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 请输入存款金额: ");
        int number=s.nextInt();
        a.setAccountbalance(a.getAccountbalance() + number);
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 当前账户存款操作成功 ");
        System.out.println(" 当前账户余额为"+a.getAccountbalance()+"元 ");
        System.out.println(" ************************************************* ");
        Menu();
        System.out.println(" 请继续操作 ");
    }
    //取款
    public static void getmoney() {
        a.setAccountbalance(a.getAccountbalance());
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        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(" ************************************************* ");
        int num1=100,num2=500,num3=1000,num4=1500,num5=2000,num6=5000;
        int str=s.nextInt();
        if (a.getAccountbalance() <str ){
          System.out.println("账户余额不足!! ");
          str=0;
        }else if(str==1){
            a.setAccountbalance(a.getAccountbalance() - num1);
        }else if(str==2){
            a.setAccountbalance(a.getAccountbalance() - num2);
        }else if(str==3){
            a.setAccountbalance(a.getAccountbalance() - num3);
        }else if(str==4){
            a.setAccountbalance(a.getAccountbalance() - num4);
        }else if(str==5){
            a.setAccountbalance(a.getAccountbalance() - num5);
        }else if(str==6){
            a.setAccountbalance(a.getAccountbalance() - num6);
        }else if(str==7){
            
            str=s.nextInt();
            a.setAccountbalance(a.getAccountbalance() - str);
        }else if(str==8){
            System.out.println("退卡成功 ");
        }else if(str==9){
            System.out.println("返回成功 ");
        }
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 当前账户存款操作成功 ");
        System.out.println(" 当前账户余额为"+a.getAccountbalance()+"元 ");
        System.out.println(" ************************************************* ");
         Menu();
        }
 
    //转账汇款
    public static void moneygogogo() {
        a.setAccountbalance(a.getAccountbalance());
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 请输入转账账户 ");
        String str=s.next();
        if(a.getAccountID().equals(str)) {
            System.out.println(" ************************************************* ");
            System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
            System.out.println(" ************************************************* ");
            System.out.println(" 请输入转账金额 ");
            int num=s.nextInt();
            if(a.getAccountbalance()<=num){
                System.out.println("账户余额不足 ");
            }else {
                a.setAccountbalance(a.getAccountbalance() - num);
                System.out.println(" ************************************************* ");
                System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
                System.out.println(" ************************************************* ");
                System.out.println(" 当前账户向"+a.getAccountID()+"成功转账"+str+"元");
                System.out.println(" 当前账户余额为"+a.getAccountbalance()+"元 ");
                System.out.println(" ************************************************* ");
            }
        }
        Menu();
    }
    //修改密码
    public static void update() throws IOException {
        fileout();
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.println(" 请输入当前密码: ");
        String str=s.next();
        if(!a.getAccountpassword().equals(str)) {
            System.out.println("当前密码录入错误");
        }else {
            System.out.println(" 请输入修改密码: ");
            String str1=s.next();
            System.out.println(" 请输入确认密码: ");
            String str2=s.next();
            if(!str1.equals(str2)) {
                System.out.println("修改密码与确认密码不一致 ");
            }else {
                System.out.println(" ************************************************* ");
                System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
                System.out.println(" ************************************************* ");
                System.out.println(" 当前账户密码修改成功");
                System.out.println(" ************************************************* ");
            }
        }
        Menu();
    }
    //查询余额
    public static void moneyhere() {
        System.out.println(" ************************************************* ");
        System.out.println("   欢迎全世界最有钱的人使用中国工商银行自助柜员系统 ");
        System.out.println(" ************************************************* ");
        System.out.print(" 当前账户余额为"+a.getAccountbalance()+"元 ");
        System.out.print(" 账户清单信息为: ");
        System.out.print(" 操作日期"+a.getOperatedate()+" 操作类型"+a.getOperatetype()+"操作金额"+a.getAmount()+" ");
        System.out.println(" ************************************************* ");
        Menu();
    }
 }
 
原文地址:https://www.cnblogs.com/cdl-sunshine/p/13715288.html