package ATM;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Account{ private String number=null; private String name=null; private String password=null; private double money=0.0; public Account(String number,String name,String password,double money) { this.number=number; this.name=name; this.password=password; this.money=money; }
public String getNumber() { return number; }
public String getName() { return name; }
public String getPassword() { return password; }
public double getMoney() { return money; }
protected void sub_Balance(double mon) { money-=mon; } protected void add_Balance(double mon) { money+=mon; } }
class ATM { Account act; public ATM() { act=new Account("000", "test", "111", 5000); } protected void Welcome() { String str="------------------------"; System.out.print(str+"
"); System.out.println("1.取款。"+"
"+ "2.查询。"+"
"+ "3.存款."+"
"+ "4.退出系统."+"
"); System.out.println(str+"
"); } protected void Load_Sys() throws Exception { String card,pwd; int counter=0; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); do { System.out.println("请输入您的卡号"); card=br.readLine(); System.out.println("请输入您的密码"); pwd=br.readLine(); if(!isRight(card,pwd)) { System.out.println("您的卡号或密码输入有误。"); counter++; } else SysOpter(); } while (counter<3); System.exit(1); } protected void SysOpter() throws Exception { int num; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("请选择您要操作的项目(1-4):"); num=br.read(); switch(num) { case 49:GetBalance();break; case 50:Inqu_Info();break; case 51:AddBalance();break; case 52:Exit_Sys();break; } System.exit(1); } protected void Inqu_Info()throws Exception { System.out.println("-------------------------
"+ "账户:"+act.getNumber()+"
"+ "姓名:"+act.getName()+"
"+ "余额:"+act.getMoney()+"
"+ "----------------------
"); SysOpter(); } public void GetBalance()throws Exception { String str=null,str1; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); do{ System.out.println("请输入取款数目:"); str=br.readLine(); double qu=Double.valueOf(str).doubleValue(); if(qu>act.getMoney()) { System.out.println("余额不足,请重新输入您要取的数目:"); } else { act.sub_Balance(qu); System.out.println("取款成功,您的账户余额为:"+act.getMoney()); Welcome(); SysOpter(); } }while(true); } public void AddBalance()throws Exception { String str=null,str1; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); do { System.out.println("请输入存款数目"); str=br.readLine(); double qu=Double.valueOf(str).doubleValue(); act.add_Balance(qu); System.out.println("存款成功,您的账户余额为:"+act.getMoney()); Welcome(); SysOpter(); }while(true); } protected boolean isBalance() { if(act.getMoney()<0) { return false; } return true; } protected boolean isRight(String card,String pwd) { if(act.getNumber().equals(card)&&act.getPassword().equals(pwd)) return true; else return false; } protected void Exit_Sys(){ System.out.println("感谢您使用本系统,再见!"); System.exit(1); } } public class Test { public static void main(String[] args)throws Exception { ATM atm=new ATM(); atm.Welcome(); atm.Load_Sys(); }