当前位置: 代码迷 >> Eclipse >> 求好手来解答个
  详细解决方案

求好手来解答个

热度:28   发布时间:2016-04-23 02:11:14.0
求高手来解答个
Java code
package Bank;//Create New Class BankAccountpublic class BankAccount {    private long accountNum;    private long passWord;    private String name;    private long ID;    private long balance;        public BankAccount(){        this.balance=0;    }//    public BankAccount(long a,long p,String n,long ID,long b){//        this.accountNum=a;//        this.passWord=p;//        this.name=n;//        this.ID=ID;//        this.balance=b;//    }    public long getAccountNum(){        return this.accountNum;    }    public long getPassWord(){        return this.passWord;    }    public String getName(){        return this.name;    }    public long getID(){        return this.ID;    }    public long getBalance(){        return this.balance;    }    public void setAccountNum(long a){        this.accountNum=a;    }    public void setPassWord(long p){        this.passWord=p;    }    public void setName(String n){        this.name=n;    }    public void setID(long ID){        this.ID=ID;    }    public void setBalance(long b){        this.balance=b;    }    public boolean comparePassWord(long i,long j){        if(i==j)            return true;        else            return false;    }    public void printIfo(){        System.out.println("AccountNumber: "+getAccountNum()+"\nName: "+getName()+"\nBalance: "+getBalance());    }}


Java code
package Bank;//Operations of Bankimport java.util.Scanner;public class BankMethods{    BankAccount acc=new BankAccount();    Scanner input=new Scanner(System.in);    long accountNum,passWord,ID,balance;    String name;        //注册    public void Register(){        //用户名        System.out.println("Input Your Account Number: ");        accountNum=input.nextLong();        boolean flag=true;        while(flag){            if((accountNum>=1*Math.pow(10,16))||(accountNum<1*Math.pow(10,15))){                System.out.println("Wrong Accounmt number, input again: ");                Scanner input=new Scanner(System.in);                accountNum=input.nextLong();                flag=true;                }            else{                acc.setAccountNum(accountNum);                System.out.println("AccountNumber Aviliable.");                flag=false;            }        }        //设置密码        System.out.println("Input Your PassWord: ");        passWord=input.nextLong();        boolean flag1=true;        while(flag1){            if((passWord>=1*Math.pow(10,6))||(passWord<1*Math.pow(10,5))){            System.out.println("Wrong Number, input again: ");            Scanner input=new Scanner(System.in);            passWord=input.nextLong();            flag1=true;            }            else{                System.out.println("Input Your PassWord Again: ");                long passWord1=input.nextLong();                if(passWord1!=passWord){                    System.out.println("Wrong Number, input again: ");                    passWord=input.nextLong();                    flag1=true;                }                else{                    acc.setPassWord(passWord);                    System.out.println("passWord Aviliable.");                    flag1=false;                }            }        }        //开户人姓名        System.out.println("Input Your Name: ");        name=input.next();        acc.setName(name);        //身份证号码        System.out.println("Input Your ID: ");        ID=input.nextLong();        boolean flag2=true;        while(flag2){            if((ID>=1*Math.pow(10,18))||(ID<1*Math.pow(10,17))){                System.out.println("Wrong ID NUmber, input again: ");                Scanner input=new Scanner(System.in);                this.ID=input.nextLong();                flag2=true;            }            else{                acc.setID(ID);                System.out.println("ID Avilliable.");                flag2=false;                System.out.println("Registration Successed");                Login();            }        }        System.exit(1);    }        //登录    public boolean Login(){        boolean flag=false;        boolean flag1=true;        System.out.println("Login: ");        while(flag1){            System.out.println("Input Your Account Number: ");            accountNum=input.nextLong();            if(accountNum==(acc.getAccountNum())){                flag1=false;                boolean flag2=true;                while(flag2){                    System.out.println("Input Your PasWord: ");                    passWord=input.nextLong();                    if(passWord==(acc.getPassWord())){                        System.out.println("Progressing, Please wait...");                        flag=true;                        flag2=false;                    }                    else{                        System.out.println("Wrong PasssWord, Input Again: ");                        flag2=true;                    }                }            }            else{                System.out.println("Error: Account Does not exits. Input again: ");                flag1=true;            }        }        return flag;    }        //取款    public void Withdrawals(){        if(Login()){            System.out.println("Input The Amount You want to Withdrawals: ");            int money=input.nextInt();            balance-=money;            if(balance<0){                System.out.println("You Don't Have Enough Money In this Account, Try Annother Amount.");            }            else{                acc.setBalance(balance);                System.out.println("Progressing, Please Wait...");                System.out.println("You Got "+balance+" Left In Your Account.");            }                    }    }        //存款    public void Deposit(){        if(Login()){            System.out.println("Input The Amount You Want To Deposit: ");            int money=input.nextInt();            balance+=money;            acc.setBalance(balance);            System.out.println("Deposit Successed, You Got "+balance+" Left In Your Account.");        }    }        //转账    public void transfer(){        if(Login()){            System.out.println("Input The Account You Want To Transfer To:");            long account=input.nextLong();            boolean flag=true;            while(flag){            if((account>=1*Math.pow(10,17))||(account<1*Math.pow(10,16))){                System.out.println("Wrong Accounmt number, input again: ");                Scanner input=new Scanner(System.in);                account=input.nextLong();                flag=true;                }            else{                System.out.println("Input The Account Again:");                long account1=input.nextLong();                if(account1!=account){                    System.out.println("Wrong Account NUmber, Input Again:");                    account=input.nextLong();                    flag=true;                    }                else{                    System.out.println("Input The Amount You Want To Transfer: ");                    int money=input.nextInt();                    balance-=money;                    acc.setBalance(balance);                    System.out.println("Transfer Successed, You Got "+balance+"Left In Your Account.");                }                }            }        }    }        //用户信息    public void Infor(){        if(Login()){            acc.printIfo();        }    }        //修改密码    public void ChangePassWord(){        if(Login()){            System.out.println("Input Your New PassWord: ");            passWord=input.nextLong();            boolean flag=true;            while(flag){                if((passWord>=1*Math.pow(10,7))||(passWord<1*Math.pow(10,6))){                System.out.println("Wrong Number, input again: ");                Scanner input=new Scanner(System.in);                passWord=input.nextLong();                flag=true;                }                else{                    System.out.println("Input Your New PassWord Again: ");                    long passWord1=input.nextLong();                    if(passWord1!=passWord){                        System.out.println("Wrong Number, input again: ");                        passWord=input.nextLong();                        flag=true;                    }                    else{                        acc.setPassWord(passWord);                        System.out.println("Change Successed.");                        flag=false;                    }                }            }        }    }}
  相关解决方案