【0727作业】实现登录注册
作者:互联网
需求:
1、登录账号唯一,在注册时验证输入的账号是否可用,若已存在,则不可用,若不存在则可用
2、登录时使用账号密码进行验证
1 package login; 2 3 public class Login { 4 private String accounts;//登录账户 5 private String password;//登录密码 6 private String phone;//手机号 7 public String getPhone() { 8 return phone; 9 } 10 public void setPhone(String phone) { 11 this.phone = phone; 12 } 13 public String getAccounts() { 14 return accounts; 15 } 16 public void setAccounts(String accounts) { 17 this.accounts = accounts; 18 } 19 public String getPassword() { 20 return password; 21 } 22 public void setPassword(String password) { 23 this.password = password; 24 } 25 26 public Login() { 27 // TODO Auto-generated constructor stub 28 29 } 30 public Login(String accounts, String password, String phone) { 31 super(); 32 this.accounts = accounts; 33 this.password = password; 34 this.phone = phone; 35 } 36 37 }
1 package login; 2 3 import java.util.HashMap; 4 import java.util.Scanner; 5 import java.util.Set; 6 7 import com.student.Student; 8 9 public class LoginSystem { 10 static Scanner sc = new Scanner(System.in); 11 12 public static void main(String[] args) { 13 // 初始化信息 14 Login user1 = new Login("asd00000", "123456", "13900000000"); 15 Login user2 = new Login("qwe00000", "234567", "15900000000"); 16 Login user3 = new Login("zxc00000", "345678", "13800000000"); 17 18 HashMap<String, Login> map = new HashMap<>(); 19 map.put(user1.getAccounts(), user1); 20 map.put(user2.getAccounts(), user2); 21 map.put(user3.getAccounts(), user3); 22 23 System.out.println("***欢迎进入系统大厅***"); 24 System.out.println("请选择:1、登录 2、注册、3、退出系统"); 25 String change = sc.next(); 26 switch (change) { 27 case "1": 28 System.out.print("请输入登录账户:"); 29 String account = sc.next(); 30 System.out.print("请输入登录密码:"); 31 String password = sc.next(); 32 // 判断验证登录信息(核查账户与密码匹配) 33 if (map.containsKey(account) && map.get(account).getPassword().equals(password)) { 34 System.out.println("登录成功!!正在加载系统..."); 35 } else if (map.containsKey(account) && !map.get(account).getPassword().equals(password)) { 36 System.out.println("密码错误!已退出登录!"); 37 } else { 38 System.out.println("输入账户不正确!登录失败!"); 39 } 40 break; 41 case "2": 42 System.out.println("请输入注册账户:"); 43 String addAccount = sc.next(); 44 if (map.containsKey(addAccount)) { 45 System.out.println("账户已存在,注册失败!"); 46 break; 47 } else { 48 System.out.println("请输入注册密码:"); 49 String addPassword = sc.next(); 50 System.out.println("请输入手机号码:"); 51 String addPhone = sc.next(); 52 System.out.println("注册成功!"); 53 System.out.println("您的登录账户为:" + addAccount + ",登录密码为:" + addPassword + ",预留手机号为:" + addPhone); 54 } 55 break; 56 default: 57 System.out.println("成功退出登录系统!"); 58 } 59 } 60 61 }
标签:0727,登录,作业,System,String,println,password,public,out 来源: https://www.cnblogs.com/yanglanlan/p/11261095.html