zoukankan      html  css  js  c++  java
  • ATM开学测试(未完成)

    package ATM_design;
    //信1705-2 20173456 张浩
    import java.util.*;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class Account {
    
     public static List<Account> accountlist=new LinkedList<Account>();
    String accountID;
    String accountname;
    String operatedate;
    int operatetype;
    String accountpassword;
    int accountbalance;
    int amount;
    public Account() {};
    public  Account(String accountID,String accountname,String operatedate,int operatetype,String accountpassword,int accountbalance) {
    	this.accountID=accountID;
    	this.accountname=accountname;
    	this.operatedate=operatedate;
    	this.operatetype=operatetype;
    	this.accountpassword=accountpassword;
    	this.accountbalance=accountbalance;
    }
    public Account(String accountID,String accountname,String accountpassword,int accountbalance) {
    	this.accountID=accountID;
    	this.accountname=accountname;
    	this.accountpassword=accountpassword;
    	this.accountbalance=accountbalance;
    }
    public Account(String accountID,String accountname,String operatedate,int operatetype,int amount) {
    	this.accountID=accountID;
    	this.accountname=accountname;
    	this.operatedate=operatedate;
    	this.operatetype=operatetype;
    	this.amount=amount;
    }
    public  String get_accountID() {
    	return accountID;
    }
    public String get_accountname() {
    	return accountname;
    }
    public String get_operatedate() {
    	return operatedate;
    }
    public int get_operatetype() {
    	return operatetype;
    }
    public String get_accountpassword() {
    	return accountpassword;
    }
    public int get_accountbalance() {
    	return accountbalance;
    }
    public int get_amount() {
    	return amount;
    }
    public void set_accountID(String accountID) {
    	this.accountID=accountID;
    }
    public void set_accountname(String accountname) {
    	this.accountname=accountname;
    }
    public void set_operatedate(String operatedate) {
    	this.operatedate=operatedate;
    }
    public void set_operatetype(int type) {
    	this.operatetype=type;
    }
    public void set_accountpassword(String password) {
    	this.accountpassword=password;
    }
    public void set_accountbalance(int balance) {
    	this.accountbalance=balance;
    }
    public void set_amount(int amount) {
    	this.amount=amount;
    }
    public  static void  addaccount (String accountID,String accountname,String accountpassword,int accountbalance) {
    	 accountlist.add(new Account(accountID,accountname,accountpassword,accountbalance));
    }
    public static void file_in() {
    File file0 = new File("F:/eclipse/ATM", "accountinformation.txt"); 
    addaccount("20173450","zhangqiang","000001",900);//创建第一个账户并放入list中
    addaccount("20173451","zhanghao","000002",1000);//创建第二个账户
    addaccount("20173452","sunyang","000003",700);//创建第三个账户
    addaccount("20173453","lihao","000004",1200);//创建第四个账户
    addaccount("20173454","liulei","000005",8500);//创建第五个账户//创建文件对象
    try {
        if (!file0.exists()) {               //如果文件不存在则新建文件
            file0.createNewFile();           
    
        }
        FileOutputStream output = new FileOutputStream(file0);
        for(int j=0;j<accountlist.size();j++) {
        	byte[] bytes0 =accountlist.get(j).accountID.getBytes();
        	byte[] bytes1 =accountlist.get(j).accountname.getBytes();
        	byte[] bytes2 =accountlist.get(j).accountpassword.getBytes();
        output.write(bytes0);
        output.write(bytes1);
        output.write(bytes2);
        output.write(accountlist.get(j).accountbalance);
        }
        output.close();
        		}catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    }
    
    /*public static void file_out() {
    try {
    	FileInputStream input = new FileInputStream(file0);
    	 for(int j=0;j<accountlist.size();j++) {
    	    	byte[] bytes0 =accountlist.get(j).accountID.getBytes();
    	    	byte[] bytes1 =accountlist.get(j).accountname.getBytes();
    	    	byte[] bytes2 =accountlist.get(j).accountpassword.getBytes();
        input.read
    
        input.close();
        }
    	
    	
    	
    }catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }*/
    }











    package ATM_design;

    import java.util.*;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    public class AccountMannager {
        
        public static void main(String[] args) {
            String ID;
            System.out.println("***************************************************************");
            System.out.println("             欢迎使用中国工商银行自动柜员系统!");
            System.out.println("****************************************************************");
            Account a = new Account();
            a.file_in();//提前存入5组数据
            boolean temp=true;
            while(temp==true) {
                System.out.print("请输入您的账号:");
                Scanner number=new Scanner(System.in);
                 ID=number.nextLine();
                    if(ID.length()!=8) {
                    System.out.println("您输入的账号不是工商行卡号!请重新输入");
                }
                
                    if(ID.length()==8) {
                    for(int j=0;j<a.accountlist.size();j++) {
                        if(ID==a.accountlist.get(j).get_accountID()) {
                            System.out.println("已查询到您的账户");
                            System.out.println("***************************************************************");
                            System.out.println("欢迎"+a.accountlist.get(j).get_accountname()+"使用中国工商银行自助柜员系统");
                            System.out.println("请输入密码:");
                            int i=0;
                             while(i<2)
                             {
                                
                                    Scanner password=new Scanner(System.in);
                                     String pw=password.nextLine();
                            if(pw!=a.accountlist.get(j).get_accountpassword())
                            {
                                i++;
                                System.out.println("密码输入错误!");                       
                                if(i==2)
                                {
                                    System.out.println("该账号三次录入密码错误,该卡已被系统没收,请与工行及时联系处理");
                                    temp=false;
                                    break;    
                                }
                            }
                            else {
                            System.out.println("***************************************************************");
                            System.out.println("欢迎"+a.accountlist.get(j).get_accountname()+"使用中国工商银行自助柜员系统");
                            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("请输入您要进行的操作序号:");
                            String op;
                            Scanner operator=new Scanner(System.in);
                            op=operator.nextLine();
                            switch(op) {
                            case "1":
                                System.out.println("***************************************************************");
                                System.out.println("欢迎"+a.accountlist.get(j).get_accountname()+"使用中国工商银行自助柜员系统");
                                System.out.println("***************************************************************");
                                System.out.println("请输入您的存款金额:");
                                int save_money;
                                Scanner save=new Scanner(System.in);
                                save_money=save.nextInt();
                                if(save_money>0) {
                                    System.out.println("***************************************************************");
                                    System.out.println("欢迎"+a.accountlist.get(j).get_accountname()+"使用中国工商银行自助柜员系统");
                                    System.out.println("***************************************************************");
                                    System.out.println("          当前账户存款成功!");
                                    System.out.println("当前账户余额为:"+(a.accountlist.get(j).get_accountbalance()+save_money)+"元");
                                    System.out.println("***************************************************************");
                                    System.out.println("若要进行其他操作需要重新录入密码:");
                                    break;
                                }
                                else {
                                    System.out.println("您输入的金额有误,请输入正整数!");
                                    System.out.println("请再次进行操作");
                                    continue;
                                }
                            case "2":
                                System.out.println("***************************************************************");
                                System.out.println("欢迎"+a.accountlist.get(j).get_accountname()+"使用中国工商银行自助柜员系统");
                                System.out.println("***************************************************************");
                                System.out.println("              当前账户每日可支取两万元。");
                                System.out.println("              1、100元 2、500元 3、1000元 4、1500元 5、2000元 6、5000元 7、其他金额 8、退卡 9、返回");
                                Scanner chioce=new Scanner(System.in);
                                int cho=chioce.nextInt();
                                switch(cho) {
                                case 1:
                                    if(a.accountlist.get(j).get_accountbalance()<100) {
                                        System.out.println("余额不足请重新选择:");
                                        Scanner cho;
                                    }
                                }
                            }
                            }
                                
                              }
                            if(temp==false)
                                break;
                        }
                        
                    }
                }
            }
      代码只写到了取款,而且对于文件的操作处理的不是很好,感觉自己能力有点跟不上老师的出题节奏啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~以后会继续努力~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!
  • 相关阅读:
    PHP学习笔记(三)
    简单的学习心得:网易云课堂Android开发第六章SQLite与ContentProvider 熊,我
    简单的学习心得:网易云课堂Android开发第三章自定义控件 熊,我
    简单的学习心得:网易云课堂Android开发第五章SharedPreferences与文件管理 熊,我
    简单的学习心得:网易云课堂Android开发第四章服务、广播与酷特性 熊,我
    本地Server发布外网Web应用(Oray实现)
    玩玩微信公众号Java版之准备
    C语言的第零次作业
    C语言博客作业02循环结构
    C语言博客作业03函数
  • 原文地址:https://www.cnblogs.com/zhang188660586/p/9697107.html
Copyright © 2011-2022 走看看