• Java第一次考试作业


    这次考试感觉自己充分的意识到自己的不足,对于Java没有系统的理解,敲程方面也有很大问题,本次程序题目为ATM机的账户记录Account有账户的唯一性标识,用户的姓名,操作日期(Date),操作类型,账户密码,当前的余额。定义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,表示操作流水金额。对每个变量定义get())和set()的方法。定义accountinformation.txt作为账户基本信息库,基本信息包括accountID,accountname,accountpassword, accountbalance,要求事先实现至少存储五个账户的信息,定义accountlist.txt作为账户操作流水信息数据库,操作流水信息包括(accountID,accountname,operatedate,operatetype, amount)。其功能要求为该程序模拟ATM的功能设计,当用户插卡后显示,输入密码界面,用户输入正确密码(用户输入错误密码,则提示该卡已被锁定,无法操作),则弹出选择界面:存款、取款、转账汇款、修改密码、查询余额。

    个人感觉通过此次编程自己又学到了很多,比如界面输出语句的具体使用方法,Java中输入输出b语句的使用,Java中判断所输入数据是否为正整数,感觉自己假期的学习还是很的不足,差了很多,深刻的认识到了自己的不足,也打算在接下来的时间里好好学习代码,就像建民欧巴说的这次的成绩并不是很重要,重要的是通过这次自己学到了什么,认识到自己有哪些不足,并从这次的错误中看到自己的不足,并学会他,搞定他,最终能够成功的运用它,毕竟自己脑袋里的东西最重要,熟练应用自己的知识也很重要,我觉得通过这次自己也真的意识到到底差在哪里和别人的差距在哪里,自己又有哪些不足的,最后,既然自己选择了这个专业,那就一定要对的起自己的选择,也相信自己会在这半年的学习中让自己更加的优秀

    package moniATM;
    import java.io.UnsupportedEncodingException;
    import java.io.UnsupportedEncondingException;
    import java.nio.charset.Charset;
    import java.util.scanner;
    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() {
        }
    
        public Account(String IDcard, String Name, String Adress, String password,
                int balance) {
            this.accountID = accountID;
            this.accountname = accountname;
            this.operatedate = operatedate;
            this.operatetype=operatetype;
            this.accountpassword = accountpassword;
            this.accountbalance = accountbalance;
        }
    
        public void setaccountname(String acccountname) {
            this.accountname = accountname;
        }
    
        public void setsetaccountID() {
            this.accountID = accountID;
        }
    
        public void setoperatedate(String operatedate) {
            this.operatedate = operatedate;
        }
    
        public void setoperatetype(int operatetype) {
            this.operatetype =operatetype;
        }
    
        public void setaccountpassword(String accountpassword) {
            this.accountpassword = accountpassword;
        }
    
        public void setaccountbalance(int accountbalance) {
            this.accountbalance = accountbalance;
        }
    
        public void setamount(int amount) {
            this.amount = amount;
        }
    
        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 void setAccount() {
            // TODO Auto-generated method stub
            
        }
    }
    
        
       
    package moniATM;
    
    import java.io.FileWriter;
    import java.io.PrintWriter;
    import java.io.UnsupportedEncodingException;
    import java.io.UnsupportedEncondingException;
    import java.util.Scanner;
    
    import com.sun.codemodel.internal.writer.FileCodeWriter;
    
    
    public class AccountManager
    {
        public Object accountID;
        public Object accountpassword;
    
        public class Main
        {
            private static final String NULL = null;
            private Object system;
            public void main(String[] args) throws UnsupportedEncodingException {
                char choise;
                int i = 0;        
                boolean flag;//判断标识
                Scanner sc = new Scanner(System.in);
                Account[] array = new Account[100];
                public void setList(int i,ArrayList<Account> ac)
                {
                    try
                    {
                        Account a=ac.get(i);
                    
                    }
                    catch(Exception e)
                    {
                        System.out.println("文件写入失败");
                    }
                }
                for (int n = 0; n < 100; n++) {
                    array[n] = new Account("asd", "asd", "asd", "asd", 1);
                }
                do {            
                    System.out.println("|**********************************************|");
                    System.out.println("|                  欢迎使用中国工商银                                                         |");
                    System.out.println("|**********************************************|");
                    System.out.println("|                    请输入您的账号                                                           |");
                    System.out.println("|**********************************************|");
                    System.out.println("");
                    boolean isNULL;
                    if(isNULL)
                    {
                        System.out.println("|**********************************************|");
                        System.out.println("|                该卡不是工商卡                                                                        |");
                        System.out.println("|**********************************************|");
                    }
                    else {
                    System.out.println("********************************************");
                    System.out.println("              欢迎使用中国工商银行自助柜员系统                                ");
                    System.out.println("********************************************");
                    System.out.println("                   请输入您的密码                                                        ");
                    System.out.println("********************************************");
                    }
                    public void setInformation(ArrayList<Account> ac)//写入信息
                    {
                        try
                        {
                            int i=0;
                            FileWriter fw=new FileWriter("AccountInformation");
                            PrintWriter pw=new PrintWriter(fw);
                            for(i=0;i<ac.size();i++)
                            {
                            
                                pw.println(((Object) ac.get(i)).getAccountID()+" "+((Object) ac.get(i)).getAccontpassword()+" "+ ac.get(i).getAccountname()+" "+ac.get(i).getAccountbalance());
                            }
                            pw.flush();
                            pw.close();
                            fw.close();
                        }
                
                    {
                        System.out.println("|**********************************************|");
                        System.out.println("|               密码输入错误,请重新输入                                                      |");
                        System.out.println("|**********************************************|");
                        counter++;
                    }while(counter<3);
                    Lock_Sys();
                    
                    
                    
                    
                    if(isRight(accountID,accountpassword))
                    {
                        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("|**********************************************|");
                    }
                    
        
                    switch (choise) {
                    case '1':
                         System.out.println("|**********************************************|");
                         System.out.println("|             欢迎使用中国工商银行自助柜员系统                                            |");
                         System.out.println("|                   请输入存款金额                                                               |");
                         System.out.println("|**********************************************|");
                         if(isNULL)
                         { 
                         System.out.println("|**********************************************|");
                         System.out.println("|             输入金额有误,返回取款页面                                                         |");
                         }
                         else
                         {
                             System.out.println("|**********************************************|");
                             System.out.println("|             欢迎使用中国工商银行自助柜员系统                                            |");
                             System.out.println("|**********************************************|");
                             System.out.println("|                     存款成功 现金额为                                                   |");
                         };
                            
                        
                        
                    case '2':{
                        int amount;
                    
                        System.out.println("|**********************************************|");
                        System.out.println("|               欢迎使用中国工商银行自助柜员系统                                    |");
                        System.out.println("|**********************************************|");
                        System.out.println("|                 当前账户每日可支取2万元                                                |");
                        System.out.println("|                 1.100元                                                                               |");
                        System.out.println("|                 2.200元                                                                               |");
                        System.out.println("|                 3.500元                                                                               |");
                        System.out.println("|                 4.1000元                                                                            |");
                        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 t;
                        t = sc.nextInt();
                            switch (t) {
                            case 1:amount = 100;break;
                            case 2:amount = 200;break;
                            case 3:amount = 500;break;
                            case 4:amount = 1000;break;
                            case 5:amount = 2000;break;
                            case 6:amount = 5000;break;
                            
                            }
                            if(amount>array[0].getaccountbalance())
                                System.out.println("余额不足");
                        
                    }
                           
                    case '3':
                        System.out.println("|**********************************************|");
                        System.out.println("|               欢迎使用中国工商银行自助柜员系统                                    |");
                        System.out.println("|**********************************************|");
                        System.out.println("|                    请输入转账金额                                                            |");
                        System.out.println("|**********************************************|");
                        array[0].setamount(sc.nextInt());
                        Account a=new Account();
                        Account b=new Account();
                        Scanner input=new Scanner(System.in);
                        String z="",x="";
                        int t=0,m=0,f1=0;
                        while(f1==0)
                        {
                            face(i,6,ac);
                            z=input.next();
                            if((t=id(z,ac))>=0)//判断
                            {
                                try
                                {
                                    face(i,7,ac);
                                    m=input.nextInt();
                                    if(m<=0)throw new Exception();
                                }
                                catch(Exception e)
                                {
                                    face(i,13,ac);
                                    f1=1;
                                    continue;
                                }
                                
                                if(f1==0)//输入正确 开始转账
                                {
                                    a=ac.get(i);
                                    b=ac.get(t);
                                    a.setAmount(-m);
                                    b.setAmount(m);
                                    ac.set(i, a);
                                    face(i,t,1,ac);
                                    x=input.next();
                                    if(x.equals("Y")==true)
                                    {
                                        a.setOperatedate();
                                        a.setOperatetype(3);
                                        b.setOperatedate();
                                        b.setOperatetype(3);
                                        if(ac.get(i).getAccountbalance()>=m)
                                        {
                                        a.setAccountbalance(a.getAccountbalance()-m);
                                        ac.set(i, a);
                                        setList(i, ac);
                                        b.setAccountbalance(b.getAccountbalance()+m);
                                        ac.set(t, b);
                                        setList(t, ac);
                                        setInformation(ac);
                                        face(i,t,2,ac);
                                        break;
                                        }
                                        else
                                        {
                                            face(i,19,ac);
                                            break;
                                        }
                                        
                                    }
                                    else if(x.equals("N")==true)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        face(i,20,ac);
                                    }
    
                                }
                            }
                        }
                    }
                
                        
                        
                    case '4':
                        System.out.println("|**********************************************|");
                        System.out.println("|               欢迎使用中国工商银行自助柜员系统                                    |");
                        System.out.println("|**********************************************|");
                        System.out.println("|                    请输入当前密码                                                            |");
                        System.out.println("|                    请输入修改密码                                                           |");
                        System.out.println("|                    请输入确认密码                                                            |");
                        public int id(String accountID,ArrayList<Account> ac)
                        {
                            int i=0,t=0;
                            if(accountID.length()!=8)
                            {
                                return -2;
                            }
                            for(t=0;t<accountID.length();t++)
                            {
                                if(accountID.charAt(t)<'0'||accountID.charAt(t)>'9')
                                {
                                    return -2;
                                }
                            }
                            for(i=0;i<ac.size();i++)
                            {  
                                if(ac.get(i).getAccountID().equals(accountID)==true)
                                {
                                    return i;
                                }
                            }
                            return -1;
                        }
                    
                        
                    case '5':
                        System.out.println("|**********************************************|");
                        System.out.println("|               欢迎使用中国工商银行自助柜员系统                                    |");
                        System.out.println("|**********************************************|");
                        System.out.println("|                    当前账户余额为: "+array[0].getaccountbalance()+"  元                                                |");
                        System.out.println("|                    账户清单信息为                                                           |");
                        System.out.println("|  1.操作日期                            操作类型                    操作金额                                            |");
                        
                        public int login(int i,String accountpassword,ArrayList<Account> ac)
                        {
                            int t=0;
                            if(accountpassword.length()!=6)
                            {
                                return -1;
                            }
                            for(t=0;t<accountpassword.length();t++)
                            {
                                if(accountpassword.charAt(t)<'0'||accountpassword.charAt(t)>'9')
                                {
                                    return -1;
                                }
                            }
                            if(ac.get(i).getAccontpassword().equals(accountpassword)==true)
                            {
                                return 1;
                            }
                            else
                            {
                                return -1;
                            }
                    
                        
                    }
                        
                        
                    
                
                    
  • 相关阅读:
    测开之函数进阶· 第4篇《匿名函数》
    函数进阶· 第3篇《常用内置函数filter()、map()、zip(),怎么用的呢?》
    测开之函数进阶· 第1篇《递归函数》
    测开之数据类型· 第4篇《迭代器、生成器》
    数据类型· 第1篇《元组和列表的性能分析、命名元组》
    Appium上下文和H5测试(二)
    聊聊「测试分工和测试时间」
    Ui Automator 框架和Ui Automator Viewer你会用吗?附送「必备adb命令」拿走不谢 !
    使用Typora+PicGo配置Gitee图床
    持续集成有什么好处?快来看鸭
  • 原文地址:https://www.cnblogs.com/love-nan/p/9697049.html
Copyright © 2020-2023  润新知