intdrawMoney(int money) { if(money<=this.money){ //System.out.println(person+": Do you wan to draw "+money+"¥?"); this.money=this.money-money; System.out.println(person+": Your accout now has "+this.money+"¥.\n"); returnthis.money; } else{ System.out.println(person+": Your accout is not enough,please check again.\n"); return0; } }
intdepositMoney(int money) { this.money+=money; System.out.println(person+": Your accout now has "+this.money+"¥.\n"); returnthis.money; }
inttransferAccounts(ATM others,int money) { if(money<=this.money){ drawMoney(money); others.depositMoney(money); returnthis.money; } else{ System.out.println(person+": Your account is not enough,please check again."); return0; } } publicstaticvoidmain(String[] args) { Scanner sc=newScanner(System.in); ATM atm=newATM("Locez"); System.out.println("Please enter your password"); while(true){ if(atm.verifyPassword(sc.next())) break; if(atm.getTimes()>=3){ System.out.println("Your account has benn locked."); System.exit(0); } } while(true) { System.out.println("********************************"); System.out.println(" Hello "+atm.person+" Money : "+atm.getMoney()+"¥"); System.out.println("********************************"); System.out.println("1.Deposit money;\n2.Draw money;\n3.Transfer accouts;\n4.Exit."); int i=sc.nextInt(); switch(i) { case1:{ int flag; System.out.println("Please enter the amount you want to deposit."); int temp=sc.nextInt(); System.out.println("Please make sure you have the amount you want to deposit.\n"+temp+"¥\n1.ok 2.exit\n"); flag=sc.nextInt(); if(flag==1){ atm.depositMoney(temp); break; } else{ System.out.println("You hava cancelled your action.\n"); break; } } case2:{ int flag; System.out.println("Please enter the amount you want to draw."); int temp=sc.nextInt(); System.out.println("Please make sure you have the amount you want to draw.\n"+temp+"¥\n1.ok 2.exit\n"); flag=sc.nextInt(); if(flag==1){ atm.drawMoney(temp); break; } else{ System.out.println("You hava cancelled your action.\n"); break; } } case3:{ int flag; System.out.println("Please enter the account name."); String account_name=sc.next(); System.out.println("Please enter the amount you want to transfer."); int temp=sc.nextInt(); System.out.println("Please make sure the information \nAcconu:"+account_name+"\nMoney:"+temp+"¥\n1.ok 2.exit\n"); flag=sc.nextInt(); if(flag==1){ atm.transferAccounts(ATM.getATM(account_name),temp); break; } else{ System.out.println("You hava cancelled your action.\n"); break; } } case4:System.out.println("Please take away your card.Good Bye!\n");System.exit(0); } } } }