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) { } } }
实现ATM登录注册
最新推荐文章于 2023-03-01 09:16:18 发布