import java.util.*; public class ATMRe { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //如果使用的是Account类数组,可以使用以下方式直接add添加 //目前其中只有获得余额的方法 Vector<Information> ac=new Vector<Information>(); Scanner in=new Scanner(System.in); Manage test=new Manage("Tom","6212260402013456234","123456",1000); int c1,c2; System.out.println("请输入密码"); String p=in.next(); if(p.equals(test.getpassword())) { while(true) { test.window(); System.out.println("请选择"); c1=in.nextInt(); test.setchoice(c1); if(test.getchoice()==1) { System.out.println("请输入存款金额"); double x=in.nextDouble(); test.deposit(x); System.out.println("用户余额为"+test.getbalance()+"元"); } if(test.getchoice()==2) { test.withdrawwindow(); System.out.println("请选择"); c2=in.nextInt(); if(c2==8) break; else { test.withdraw(c2); System.out.println("用户余额为"+test.getbalance()+"元"); } } if(test.getchoice()==3) { System.out.println("请输入转账卡号、转账金额"); String n=in.next(); double m=in.nextDouble(); test.transfer(n, m); System.out.println("用户余额为"+test.getbalance()+"元"); } if(test.getchoice()==4) { System.out.println("请输入修改的密码(6位)"); String z=in.next(); test.setpassword(z); if((test.getpassword()).equals(z)) System.out.println("修改成功"); else { System.out.println("修改失败,请重新选择修改密码操作"); } } if(test.getchoice()==5) { System.out.println("用户余额为"+test.getbalance()+"元"); } } } else { System.out.println("用户输入错误密码,该卡已被锁定,无法操作!"); } } } class Information { public void outputbalance(Vector<Account> ac) { for(Account a:ac) { a.getbalance(); } } } class Manage extends Account { Manage(String n,String i,String p,double b) { name=n; id=i; password=p; balance=b; } public void window() { System.out.println("************"); 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("************"); } public void withdrawwindow() { System.out.println("************"); System.out.println("取款窗口"); System.out.println("1.100"); System.out.println("2.500"); System.out.println("3.1000"); System.out.println("4.1500"); 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("************"); } public void withdraw(int c) { choice=c; if(choice==1) balance=balance-100; if(choice==2) balance=balance-500; if(choice==3) balance=balance-1000; if(choice==4) balance=balance-1500; if(choice==5) balance=balance-2000; if(choice==6) balance=balance-5000; if(choice==7) { System.out.println("请输入存款金额"); double x=input.nextDouble(); balance=balance-x; } if(choice==9) window(); } public void deposit(double d) { balance=balance+d; } public void transfer(String a,double t) { if(balance>=t) { balance=balance-t; System.out.println("转账成功"); } else { System.out.println("余额不足,无法转账"); } } } class Account { Scanner input=new Scanner(System.in); public String id; public String name;//姓名 public int choice;//操作 public String password;//密码 public double balance;//余额 Account(){} public double getbalance() { return balance; } public void setchoice(int c) { choice=c; } public int getchoice() { return choice; } public String getpassword() { return password; } public void setpassword(String p) { password=p; } }