package com.lovo.atmoo.bean;
import java.util.Scanner;
public class ATMachine {
	
	private UserBean theUser;//ATM中记录的用户信息
	
	private int cash;//现金
	
	public final int MAX_CASH = 200000;
	
	public ATMachine(){
		//创建假的预存数据
		this.theUser = new UserBean("J142","123456",110);
		this.cash = 100000;
		
		this.run();
	}
	
	//运行---控制ATM运行流程的
	private void run(){
		this.welcome();
		boolean flag = this.login();
		if(flag){
			while(true){
				int choice = this.chooseMenu();
				switch(choice){
				case 1:
					this.query();
					break;
				case 2:
					this.getMoney();
					break;
				case 3:
					this.storeMoney();
					break;
				case 4:
					this.changePwd();
					break;
				case 5:
					this.exit();
					break;
				default:
					System.out.println("没有该选项,请仔细读取提示信息。");
					break;
				}
			}
		}else{
			System.out.println("三次登录失败,您的卡被没收。");
			System.out.println("请持有效证件到柜台处理!");
		}
	}
	
	private void welcome(){
		System.out.println("**********************************");
		System.out.println("**************ICBC银行************");
		System.out.println("**********************************");
		System.out.println("**********************************");
		System.out.println("*********************version1.0****");
		System.out.println("**********************************");
	}
	
	private boolean login(){
		for(int i = 0; i < 3; i++){
			Scanner scan = new Scanner(System.in);
			System.out.println("请输入卡号:");
			String inputCardNum = scan.nextLine();
			System.out.println("请输入密码:");
			String inputPwd = scan.nextLine();
			if(inputCardNum.equals(this.theUser.getCardNum()) &&
					inputPwd.equals(this.theUser.getPassword())){
				System.out.println("欢迎你,"+ inputCardNum + ",登录成功!");
				return true;
			}else{
				System.out.println("卡号密码有误,请查证!你还有" + (2 - i) + "次机会!");
			}
		
		}
		return false;
	}
	
	private int chooseMenu(){
		Scanner scan = new Scanner(System.in);
		System.out.println("请选择您要执行的操作:");
		System.out.println("1、查询余额;2、取款;3、存款;4、修改密码;5、退出");
		int choice = scan.nextInt();
		return choice;
	}
	
	private void query(){
		System.out.println("您当前的余额是:" + this.theUser.getAccount() + "元。");
	}
	
	private double storeMoney(){
		Scanner scan = new Scanner(System.in);
		System.out.println("请输入您要存入的金额:");
		int inputMoney = scan.nextInt();
		cash=cash+inputMoney;
		if(cash <= 200000){
		double account = this.theUser.getAccount()+inputMoney;
		System.out.println("你的余额为:"+account);
		return this.theUser.account=account;
		}else{
			System.out.println("你的存入金额过大!");
		}
		return this.theUser.account;
	}
	
	private double getMoney(){
		Scanner scan = new Scanner(System.in);
		System.out.println("请输入您要取出的金额:");
		int inputMoney = scan.nextInt();
		cash=cash-inputMoney;
		if(cash>=0){
			double account = this.theUser.getAccount()-inputMoney;
			System.out.println("你的余额为:"+account);
			return this.theUser.account=account;
		}
		if(cash<0){
			System.out.println("对不起,该ATM机器余额不足,无法取款!");
		}
		return this.theUser.account;
	}
	
	private void changePwd(){
			Scanner scan = new Scanner(System.in);
			System.out.println("请输入你的旧密码");
			String str = scan.next();
			if(str.equals("123456")){
				System.out.println("请输入新的密码:");
				String str1 = scan.next();
				System.out.println("请再次输入新的密码:");
				String str2 = scan.next();
				if(str1.equals(str2)){
					System.out.println("恭喜你,密码修改成功!");
				}else{
					System.out.println("密码修改失败!");
				}
			}else{
				System.out.println("你的密码输入有误!");
			}
	}
	
	private void exit(){
		System.out.println("谢谢您的使用,期待下次再为您服务!");
		System.exit(0);
	}
	
}
原文:http://www.cnblogs.com/HP-huoshaoxiu/p/6828151.html