zoukankan      html  css  js  c++  java
  • JAVA开学考试问题分析

    package hellopeace;
    // 信1905-2 20194199 刘佳琦
    import java.util.Scanner;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    class Account {
        String accountID;
        String accountname;
        String operatedate;
        int operatetype;
        String accountpassword;
        int accountbalance;
        int amount;
        public String getaccountID()
        {
            return accountID;
        }
        public void setaccountID(String accountID)
        {
            this.accountID = accountID;
        }
        public String getoperatedate() 
        {
            return operatedate;
        }
        public void setoperatedate(String operatedate) 
        {
            this.operatedate = operatedate;
        }
        public String getaccountname() 
        {
            return accountname;
        }
        public void setaccountname(String accountname) 
        {
            this.accountname = accountname;
        }
        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 getamount() {
            return amount;
        }
        public void setamount(int amount) {
            this.amount = amount;
        }
        public int getaccountbalance() {
            return accountbalance;
        }
        public void setaccountbalance(int accountbalance) {
            this.accountbalance = accountbalance;
        }
        Account(String accountID,String accountname,String operatedate,int operatetype,String accountpassword,int amount,int accountbalance)
        {
            this.accountID = accountID;
            this.operatedate = operatedate;
            this.operatetype = operatetype;
            this.accountpassword = accountpassword;
            this.amount = amount;
            this.accountname = accountname;
            this.accountbalance=accountbalance;
        }
    }
    
    
    public class rr {
    
        static int sum=0;
        static Scanner input = null;
        static Account[] accountinformation = new Account[1000];
        
        public static String coder() {               //输入账号
            input = new Scanner(System.in);
            String accountID;
            int k;
            int p=0;
           System.out.println("*************************************************************** 
    " + 
                   "         欢迎使用中国工商银行自动柜员系统
    " + 
                   "**************************************************************** 
    " + 
                   " 请输入您的账号
    "+
                   "**************************************************************** 
    ");
           accountID=input.next();
           if (accountID.length()!=8)
           {
               System.out.print("该卡不是工行卡
    ");
           }
           for(k=0;k<1000;k++) {
               if( accountinformation[k].accountID.equals(accountID)) {
                   p=1;
            }
       }
           return accountID;
    }
        
      public static int systemMenu() {
            input = new Scanner(System.in);
           System.out.println("***************************************************************
    "
                   +"欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    "
                   +"****************************************************************
    "
                   +"1、存款;
     "
                   +"2、取款;
    "
                   +"3、转账汇款;
     "
                   +"4、修改密码;
    "
                   +"5、查询余额;
    "
                   +"**************************************************************** ");
           int ch;
           System.out.println("请选择:");
           ch = input.nextInt();
           return ch;
       }
        
       public static int passer(String accountID) {               //输入账号
               input = new Scanner(System.in);
               String accountpassword;
               int k;
               int p=0;
               for(k=0;!(accountinformation[k].accountID.equals(accountID));k++){}
              System.out.println("*************************************************************** 
    " + 
                      "         欢迎使用中国工商银行自动柜员系统
    " + 
                      "**************************************************************** 
    " + 
                      " 请输入您的密码
    "+
                      "**************************************************************** 
    ");
              accountpassword=input.next();
              if(accountinformation[k].accountpassword.equals(accountpassword))
              {p=1;}
              sum=k;
              return p;
       }
        public static void Addaccount(String accountID,String accountname,String accountpassword,int accountbalance){
            
            int k;
            for(k=0;k<sum;k++) {
                if( accountinformation[k].accountID.equals(accountID) ) {
                    System.out.println("账户重复");
                    return;
                }
            }
            
            accountinformation[sum] = new Account(accountID,accountname,"unknow",0,accountpassword,0,accountbalance);
    
            sum++;
            }
    
    
        public static void main(String[] args) {
            File ptr=new File("C:\Users\14997\Desktop\","accountinformation.txt");
            File pan=new File(ptr.getParent());
            input=new Scanner(System.in);
            String though;
            int pro,clone,cash;
            int check=0;
            int k1;
            int ac;
            String accountID;
            String accountname;
            String operatedate;
            int operatetype;
            String accountpassword;
            int amount;
            int accountbalance;
            int choice;
            System.out.println("现在是初始创建五名用户信息(请依照用户账号、用户名、用户密码、用户余额输入):");
               for(k1=0;k1<5;k1++) {   
                  accountID = input.next();
                  accountname = input.next();
                  accountpassword= input.next();
                  accountbalance= input.nextInt();
                  rr.Addaccount(accountID,accountname,accountpassword,accountbalance);
               }
            sum=5; 
            though=coder();
            pro=passer(though);
            choice=systemMenu();
            
            while(choice<=5&&choice>=1) {
                
                switch (choice) {
                case 1:
                            System.out.print("***************************************************************
    " + 
                            "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                            "****************************************************************
    " + 
                            "请输入存款金额;
    " + 
                            "       
    " + 
                            "****************************************************************");
                            ac=input.nextInt();
                            for(;ac<0;)
                            {
                                System.out.print("输入金额错误
    ");
                                System.out.print("请重新输入金额
    ");
                                ac=input.nextInt();
                            }
                            accountinformation[sum].accountbalance=accountinformation[sum].accountbalance+ac;
                            System.out.print("***************************************************************
    " + 
                                   "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                                   "****************************************************************
    " + 
                                   "当前账户存款操作成功。
    " + 
                                   "当前账户余额为:"+accountinformation[sum].accountbalance+"元
    " + 
                                   "****************************************************************");
                            OutputStream output = System.out;
                            byte[] byten=(accountinformation[sum].accountID+" 存入"+ac+"元
    ").getBytes();
                            try {
                            output.write(byten);
                            } catch (IOException e) {}
                            
                    break;
                case 2:
                    String we="y";
                    for(;we!="q";)
                    {
                    System.out.print("***************************************************************
    " + 
                            "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                            "****************************************************************当前账户每日可以支取2万元。
    " + 
                            "1、100元
    " + 
                            "2、500元
    " + 
                            "3、1000元
    " + 
                            "4、1500元
    " + 
                            "5、2000元
    " + 
                            "6、5000元;
    " + 
                            "7、其他金额
    " + 
                            "8、退卡
    " + 
                            "9、返回
    " + 
                            "****************************************************************");
                         clone=input.nextInt();
                         switch (clone)
                         {
                            case 1:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-100;
                                if(accountinformation[sum].accountbalance<100)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output2 = System.out;
                                byte[] byten2=(accountinformation[sum].accountID+" 支出100元
    ").getBytes();
                                try {
                                output2.write(byten2);
                                } catch (IOException e) {}
                                break;
                            case 2:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-500;
                                if(accountinformation[sum].accountbalance<500)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output3 = System.out;
                                byte[] byten3=(accountinformation[sum].accountID+" 支出500元
    ").getBytes();
                                try {
                                output3.write(byten3);
                                } catch (IOException e) {}
                                break;
                            case 3:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-1000;
                                if(accountinformation[sum].accountbalance<1000)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output4 = System.out;
                                byte[] byten4=(accountinformation[sum].accountID+" 支出1000元
    ").getBytes();
                                try {
                                output4.write(byten4);
                                } catch (IOException e) {}
                                break;
                            case 4:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-1500;
                                if(accountinformation[sum].accountbalance<1500)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output5 = System.out;
                                byte[] byten5=(accountinformation[sum].accountID+" 支出1500元
    ").getBytes();
                                try {
                                output5.write(byten5);
                                } catch (IOException e) {}
                                break;
                            case 5:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-2000;
                                if(accountinformation[sum].accountbalance<2000)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output6 = System.out;
                                byte[] byten6=(accountinformation[sum].accountID+" 支出2000元
    ").getBytes();
                                try {
                                output6.write(byten6);
                                } catch (IOException e) {}
                                break;
                            case 6:
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-5000;
                                if(accountinformation[sum].accountbalance<5000)
                                {System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元");break;}
                                OutputStream output7 = System.out;
                                byte[] byten7=(accountinformation[sum].accountID+" 支出5000元
    ").getBytes();
                                try {
                                output7.write(byten7);
                                } catch (IOException e) {}
                                break;
                            case 7:
                                int c;
                                System.out.println("请输入取款金额");
                                c=input.nextInt();
                                for(;accountinformation[sum].accountbalance<c;)
                                {
                                    System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元,请重新输入");
                                }
                                accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-c;
                                OutputStream output8 = System.out;
                                byte[] byten8=(accountinformation[sum].accountID+" 支出"+c+"元
    ").getBytes();
                                try {
                                output8.write(byten8);
                                } catch (IOException e) {}
                                break;
                         }
                         System.out.println("请问要重新取款吗 按q退出");
                         we=input.next();                     
                    }
                    break;
                case 3:
                    String p;
                    System.out.print("***************************************************************
    " + 
                            "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                            "****************************************************************
    " + 
                            "请输入转账账户;
    " + 
                            "       
    " + 
                            "****************************************************************");
                    int k=1001;
                    p=input.next();
                    for (;k==1001;) 
                    {
                        for(k=0;accountinformation[k].accountID.equals(p);k++){}
                        if(k==1001)
                        {System.out.print("账户不存在,请重新输入");}
                        p=input.next();
                    }
                    int c;
                    System.out.println("请输入转账金额");
                    c=input.nextInt();
                    for(;accountinformation[sum].accountbalance<c;)
                    {
                        System.out.println("余额不足,还有"+accountinformation[sum].accountbalance+"元,请重新输入");
                    }
                    accountinformation[sum].accountbalance=accountinformation[sum].accountbalance-c;
                    OutputStream output8 = System.out;
                    byte[] byten8=(accountinformation[sum].accountID+" 支出"+c+"元
    "+accountinformation[k].accountID+" 存入"+c+"元
    ").getBytes();
                    try {
                    output8.write(byten8);
                    } catch (IOException e) {}
                    accountinformation[sum].accountbalance=accountinformation[sum].accountbalance+c;
                    break;
                case 4:
                    String self,self2="0",self3="1";
                     System.out.print("***************************************************************
    " + 
                             "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                             "****************************************************************
    " );
                     System.out.print("请输入当前密码:
    ");
                     self=input.next();
                     for(;self!=accountinformation[sum].accountID;)
                     {System.out.print("密码输入错误");self=input.next();}
                     for(;self2!=self3;)
                     {
                        System.out.print("请输入修改密码:
    ");
                        self2=input.next();
                        System.out.print("请输入确认密码:
    ");
                        self2=input.next();
                        if(self2!=self3)
                        {System.out.print("两次输入不匹配,请重新输入
    ");}
                     }
                     accountinformation[sum].accountID=self2;
                     System.out.print("****************************************************************");
                    break;    
                case 5:
                    System.out.print("***************************************************************
    " + 
                            "欢迎"+accountinformation[sum].accountname+"使用中国工商银行自助柜员系统
    " + 
                            "****************************************************************
    " + 
                            "当前账户余额为:"+accountinformation[sum].accountbalance+"元
    " + 
                            "账户清单信息为:
    ");
                    byte[] byte3 = new byte[1024];
                    
                    try {
                        InputStream inp = System.in;
                        while(inp.read() != -1){
                            String str = new String(byte3).trim();
                        }
                        inp.close();
                        
                    } catch (IOException e) {} 
                    
                    break;
                    
                }
        }
    
    }
    }

     在今天这个阴云密布的下午,我们进行了本学期的第一次JAVA考试,虽然说这次考试确实给了充裕的时间来让我们准备,但说实话考得并不好,其他不少人也都有类似的想法(当然,除了那帮搜索到题目的,我们这里有几个满分的家伙就是在考试的过程中通过题干搜索到了题目,成功骗过几位评委……当然昧良心的事不能干,这种事还是少做为好)说实在的,这次考试真的让我认识到了自己的一些不足,同时痛惜为什么没有好好熟悉JAVA语言结构。我这几个月都干了什么啊!

    因为建民老师之前给出了学生管理系统的题目作为例题,我便就此联想到了暑期技能实训中的题目安排,押题押的也与实训中题目安排相同,是学生成绩管理系统。说实话,当我第一次看到考试题目时我还是比较惊喜的,但由于一些同学已经拿到了上学期考试的源码,因此建民老师决定临时换成ATM机管理系统。虽然是不熟悉的系统,但我也硬着头皮去做了,而且一开始确实是很顺利,定义类,使用数组,文件操作都与自己所学恰好契合,因此在敲前面代码时,我甚至产生了点想快乐唱歌的冲动。

    但之后,由于我对JAVA的语言结构还是不够熟悉,导致我忽略了一个重要细节——两个String间做相关时,不可以使用==这种强相关结构,只能使用String内部定义的equals()函数来描述相等关系,但由于我过分天真地认为JAVA与C++在语法逻辑层面完全互通,因此根本没有考虑到这种事,后果就是出错出错再出错。而且这个问题是非常基础的问题,不解决它其他的代码就没有任何意义,我在这里磨磨蹭蹭了一个多小时,直接导致后面的功能都无法实现,只能先写出分支的菜单界面,根本无法细抠功能,这也是我这次成绩非常不理想的主要原因,最后半个小时其实整个人都不太好了,但没有办法,只能硬着头皮上交硬着头皮验收。所幸给我验收的那位下手不重,还给我卡了一个及格分呢!

    我本人打字速度慢,心性浮躁,因此比起长期慢性刺激,我更喜欢瞬间且迅速的刺激。与此同理我也没有采取实际上更加节省时间的“分块调试法”,而是采用了顺序编写的思路,走一步看一步,这也是不听建民言的后果。任何事都并非一蹴而就,当然也不是遇到点困难就草木皆兵,下次再有这种考试机会的话,我一定会以一个崭新的态度来积极合理地规划时间的。其实回宿舍后很快我就完成了程序的调试,实际上也就差大概半个小时的代码量,但由于我光想着去解决问题,缺乏大局观,忽略了更加简洁直白的方式,这也是我性格中一些糟糕的部分的一次集中暴露,当然我也确实在改,现在还在考虑要不要做些瑜伽之类调养心性的运动。当然,敲代码还是主业,做人可不能忘了本。

    建民老师说,这次考试绝非终结,不是打了十分JAVA就过不了,也不是打了二十分就一定能过,它只是一个发现问题的窗口。而我则信奉所谓“万事万物皆为挑战”,这次不论结果再怎么令我不满意,有多么想吃后悔药坐时光机重来,我总归也是学到了东西的,至少我知识点上学了一个String只能用equals()来描述相关关系,性格上我知道了戒骄戒躁与接受他人优秀理念的重要,还有就是要听老师话,考试要合理安排时间等等,这些就是所谓的生活经验。吃一堑才能长一智,虽然要付出不及格风险这种代价可能是有点高,但人类永远都是在错误中学习,错误中前进嘛

  • 相关阅读:
    c文件操作库
    双链常用操作2
    双向链表常用操作
    c队列操作
    c日期格式化操作之date
    单链常用操作类
    c字符串常用操作
    双向链表通用类
    c栈操作
    poj2509
  • 原文地址:https://www.cnblogs.com/Sakuraba/p/13715469.html
Copyright © 2011-2022 走看看