JAVA消息对话框版ATM机
public class ATM {
public static void main(String[] args) {
int x = 0;
for (int i = 1; i <= 3; i++) {
String code = JOptionPane.showInputDialog(null, "请输入账号:");
String pwd = JOptionPane.showInputDialog(null, "请输入密码:");
if ("123".equals(code) && "666".equals(pwd)) {
x = 1;
break;
} else {
JOptionPane.showMessageDialog(null, "账号密码输入错误!");
}
}
if (x == 1) {
JOptionPane.showMessageDialog(null, "登录成功");
} else {
JOptionPane.showMessageDialog(null, "非法用户!即将退出系统");
System.exit(0);
}
int money = 5000;
while (true) {
String item = JOptionPane.showInputDialog("请按编号选择:\n1.存款\n2.取款\n3.查询余额\n4.退出");
switch (item) {
case "1":
String deposit = JOptionPane.showInputDialog(null, "请输入您的存款金额:");
money += Integer.parseInt(deposit);
break;
case "2":
String withDrawal = JOptionPane.showInputDialog(null, "请输入您的取款金额:");
int wd = Integer.parseInt(withDrawal);
if (wd > money) {
JOptionPane.showMessageDialog(null, "当前账户余额不足!");
} else {
money -= wd;
}
JOptionPane.showMessageDialog(null, wd + "元取款成功");
break;
case "3":
JOptionPane.showMessageDialog(null, "您当前账户可用余额为:" + money + "元");
break;
case "4":
JOptionPane.showMessageDialog(null, "感谢您的使用!再见!");
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "请按指定操作!");
}
}
}
}