5.22

在打代码之前想把老师的代码先打一遍:

    //ATM机

public class ATMMachine{

//用户信息

private UserInfo user;

//现金

private int cash;

//现金容量上限

public final int MAX_CASH = 200000;

//存取上限

public final int  GET_SET_MAX = 2000;

public ATMMachine(){

//预载入用户信息

      this.user = new UserInfo("J124","123456",500);

      this.cash = 100000;

}

// 运行
public void run() {
this.welcome();
boolean flag = this.login();
if (flag) {
System.out.println("欢迎您,用户" + this.user.getUsername() + "!");
while (true) {
int choice = this.choiceMenu();
switch (choice) {
case 1:
this.query();
break;
case 2:
this.storeMoney();
break;
case 3:
this.getMoney();
break;
case 4:
this.changePwd();
break;
case 5:
this.exit();
break;
default:
System.out.println("对不起,没有该选项!");
break;
}
}
} else {
System.out.println("您的账户被冻结!请到柜台处理!");
}
}

// 显示欢迎
private void welcome() {
System.out.println("******************************");
System.out.println("*********欢**迎**登**录*********");
System.out.println("******************************");
System.out.println("*********爱存不存银行ATM*********");
System.out.println("******************************");
System.out.println("*****************version1.0***");
}

// 登录
private boolean login() {

for (int i = 0; i < 3; i++) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入您的账号:");
String inputName = scan.next();
System.out.println("请输入您的密码:");
String inputPwd = scan.next();
if (inputName.equals(this.user.getUsername())
&& inputPwd.equals(this.user.getPassword())) {
return true;
} else {
System.out.println("输入有误!您还有" + (2 - i) + "次机会");
}
}
return false;
}

// 选择菜单
private int choiceMenu() {
int choice = 0;
Scanner scan = new Scanner(System.in);
System.out.println("请选择您要执行的操作:");
System.out.println("1、查询;2、存款;3、取款;4、修改密码;5、退出");
choice = scan.nextInt();
return choice;
}

// 查询余额
private void query() {
//直接显示user对象中的account属性值
System.out.println("cha");
}

// 存钱
private void storeMoney() {
//1、接收用户输入
//2、判断--不能为0,不能为负,不能不是100的倍数,不能超过存取上限,不能超过现金容量--给出提示
//3、判断通过--加现金,加余额
System.out.println("chun");
}

// 取款
private void getMoney() {
System.out.println("qu");
}

// 修改密码
private void changePwd() {
System.out.println("gai");
}

// 退出
private void exit() {
System.out.println("谢谢您的使用!请收好您的卡!");
System.exit(0);
}

}

这是老师没有写完的代码       需要自己来完成!

但现在还没头绪    也不知道自己的真不真确      。。

等老师讲了再来完成。。

原文地址:https://www.cnblogs.com/whj1986556646/p/5516686.html