实现ATM登录注册

public class ATMtest {
    public static void main(String[] args) {
        // 1.显示页面
        while (true) {
            System.out.println("欢迎来到ATM系统");
            System.out.println("1.登录");
            System.out.println("2.注册新账户");
            System.out.println("请选择您所需要的服务(输入1或2):");
            // 选择相应服务
            Scanner sc = new Scanner(System.in);
            ArrayList<Object> accounts = new ArrayList();
            int firstSelectNumber = sc.nextInt();
            // 2.进入下一页面
            switch (firstSelectNumber) {
                // 进入登录界面
                case 1:
                    System.out.println("欢迎您进入到登录界面");
//                    System.out.println("请输入您的账户名称:");
//                    System.out.println("请输入您的账户密码:");
                    /*
                    ****暂定为判断是否登录成功(未运行不知对错)****
                    int i;
                    for( i = 1; i <= 5;i++){
                        switch (i){
                            case 1:System.out.println("您还剩5次登陆机会");
                            case 2:System.out.println("您还剩4次登陆机会");
                            case 3:System.out.println("您还剩3次登陆机会");
                            case 4:System.out.println("您还剩2次登陆机会");
                            case 5:System.out.println("您还剩1次登陆机会");
                        }
//                        if执行判断(如果登陆数据和数据库内信息不匹配)
                        {
                            System.out.println("您输入账号或密码错误,请重新输入");
                        }
//                        else{
//                            sout(恭喜您登录成功);
//                        }
                        if (i>5){
                            System.out.println("请3分钟之后重新输入!!!");  ****这里缺少定义3分钟时长的代码*****
                        }
                     }
                     */
                    break;
                // 进入注册界面
                case 2:
                    System.out.println("欢迎您进入到开户界面");
                    System.out.println("请您输入账户名称:");
                    String accountName = sc.next();
                    while(!checkaccountName(accountName)) {
                        System.out.println("用户名不合法,请重新输入:");
                        accountName=sc.next();
                    }
                    while (true) {//while死循环实现注册成功
                        System.out.println("请您输入账户密码");
                        String accountPassword = sc.next();
//                        while(!checkaccountpassword(accountPassword)) {       //问题出现在while循环
//                            System.out.println("密码不合法,请重新输入:");
//                            accountPassword= Integer.parseInt(sc.next());
//                        }
                        System.out.println("请再次输入密码");
                        String ComfirmPassword = sc.next();

                        if (ComfirmPassword.equals(accountPassword)) {
                            System.out.println("恭喜您开户成功!");
                            break;
                        }else
                        System.out.println("两次输入的密码不相同,请重新输入");
                    }
            }
            break;
        }
    }
//控制用户输入账户名及密码的条件
    public  static boolean checkaccountName(String name) {
        //必须是5-17位字母、数字、下划线随机组成
        //不能以数字开头
        String Aname = "^[a-zA-Z]\\w{5,17}$";
        if (name.matches(Aname)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean checkaccountpassword() { //保证第一次输入的accountpassword满足checkaccountpassword
        String psd = "^[a-zA-Z]\\w{8,15}$";//String类型长度更长,适合定义密码,不容易被破解
        if (psd.matches(psd))
            return true;
        else {
            return false;
        }

    }
    public class Account {
        public Account(String accountName, int accountPassword) {
        }
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值