简易ATM

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, "请按指定操作!");
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

再笨的鸟也要飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值