Java_项目实战-ATM销户、密码修改

销户操作的基本要求

  • 销户就是从系统中删除当前账户,销户的要求:
    1. 首先要询问用户是否确定销户,否,返回操作界面
  1.询问用户是否确定要销户
        System.out.println("是否确定要注销当前账户?y/n");
        String command = sc.next();
        switch (command) {
            case "y":
2. 如果确定,要判断用户的帐户中是否有钱,有,不允许销户,返回操作页面;
  判断账户中是否有钱
                if (loginAccount.getMoney() == 0) {
                } else {
                    System.out.println("账户存在余额,不能注销");
                    return false;
                }
3. 没钱,完成销户,回到欢迎页
if (loginAccount.getMoney() == 0) {
//                    可以销户
                    accounts.remove(loginAccount);
                    System.out.println("注销成功");
                    return true;
                }
4. 完整代码
private boolean deleteAccount() {
        System.out.println("----注销当前账户----");
//        1.询问用户是否确定要销户
        System.out.println("是否确定要注销当前账户?y/n");
        String command = sc.next();
        switch (command) {
            case "y":
//                确定要销户
//                判断账户中是否有钱
                if (loginAccount.getMoney() == 0) {
//                    可以销户
                    accounts.remove(loginAccount);
                    System.out.println("注销成功");
                    return true;
                } else {
                    System.out.println("账户存在余额,不能注销");
                    return false;
                }
            default:
                System.out.println("您的账户被保留");
                return false;
        }
    }

密码修改

  • 就是更改账户密码,修改密码的要求:
    1. 需要先认证用户当前的密码
2.认证当前密码是否正确
            if (loginAccount.getPassword().equals(password)) {
                //            认证通过
2. 认证通过后,需要让用户输入2次新密码
while (true) {
                    //            3.开始修改密码
                    System.out.println("请输入新密码:");
                    String newPassword = sc.next();

                    System.out.println("请输入确认密码:");
                    String confirmNewPassword = sc.next();
3. 两次密码一样,则更新账户密码,应返回欢迎界面
//            4.判断两次密码是否一致
                    if (newPassword.equals(confirmNewPassword)) {
                        //                开始修改密码
                        loginAccount.setPassword(newPassword);
                        System.out.println("密码修改成功");
                        return;
                    } else {
                        System.out.println("两次密码不一致");
                    }
4. 完整代码
//    修改密码
    private void updatePassword() {
        System.out.println("--修改密码--");

        while (true) {
//        1.提醒用户认证当前密码
            System.out.println("请输入当前密码:");
            String password = sc.next();

//        2.认证当前密码是否正确
            if (loginAccount.getPassword().equals(password)) {
                //            认证通过

                while (true) {
                    //            3.开始修改密码
                    System.out.println("请输入新密码:");
                    String newPassword = sc.next();

                    System.out.println("请输入确认密码:");
                    String confirmNewPassword = sc.next();

                    //            4.判断两次密码是否一致
                    if (newPassword.equals(confirmNewPassword)) {
                        //                开始修改密码
                        loginAccount.setPassword(newPassword);
                        System.out.println("密码修改成功");
                        return;
                    } else {
                        System.out.println("两次密码不一致");
                    }
                }
            } else {
                System.out.println("您当前输入的密码错误");
            }
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值