class ATM {
	public int ID;
	public String name;
	public double balance;// 余额
	public int password;// 密码

	public void DrawMoney(double money) {// 取钱方法
		balance -= money;
		System.out.println("当前余额为:" + balance);
	}

	public void SaveMoney(double money) {// 存款方法
		balance += money;
		System.out.println("当前余额为:" + balance);
	}
}

public class Demo7_ATM {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ATM atm = new ATM();
		atm.balance = 1000;
		atm.password = 123;
		atm.ID = 4569;
		atm.name = "王思聪";
		int i = 3;// 定义密码次数
		System.out.println("欢迎使用ATM自动银行");
		while (true) {// 循环输入密码
			System.out.println("请您的输入密码");
			int pass = sc.nextInt();

			if (pass == atm.password) {

				System.out.println("密码正确");
				System.out.println("你的ID:" + atm.ID + "名字:" + atm.name + "你的余额:" + atm.balance);
				while (true) {// 循环取款存款方法
					System.out.println("1.取款 2.存款 3.查询 4.退出");
					int option = sc.nextInt();


					if (option == 1) {
						System.out.println("输入取款金额");
						int money = sc.nextInt();
						atm.DrawMoney(money);
						// break;
					} else if (option == 2) {
						System.out.println("输入存款金额");
						int money1 = sc.nextInt();
						atm.SaveMoney(money1);
						// break;
					} else if (option == 3) {
						System.out.println("当前余额为:" + atm.balance);
						// break;
					} else if (option == 4) {
						System.out.println("谢谢使用");
						System.exit(0);//退出jvm虚拟机
					} else {
						System.out.println("你输入的有误");
					}

				}

			} else {
				i--;// 每次输入错误就这里减一次
				if (i == 0) {// 判断等于0就执行里面的语句
					System.out.println("你的账号被冻结");
					break;// 输入密码循环结束
				}
				System.out.println("你输入的密码有误,还有" + i + "机会");
			}

		}

	}

}

07-12 03:41