package com.heima.zhucebiao;
import java.util.ArrayList;
import java.util.Scanner;
public class Demo_Test1 {
/**
* 模拟登录
* 分析:
* 1,先创建一个类存储账户和密码;
* 2,创建键盘录入对象,录入密码和账户
* 3,将录好的账户密码存储到对象中,在将对象存在集合中
* 4,在登录时比较密码和账户是否相同,相同登录成功,不相同登录失败
*/
public static void main(String[] args) {
System.out.println("欢迎进入");
Scanner sc = new Scanner(System.in);
ArrayList<Demo_User> list = new ArrayList<>();
while(true){
System.out.println("1注册,2登录");
String s = sc.nextLine();
if("1".equals(s)){
System.out.println("请输入账号");
String username = sc.nextLine();
System.out.println("请输入密码");
String usernam = sc.nextLine();
Demo_User d1 = new Demo_User(username,usernam);
list.add(d1);
}else if ("2".equals(s)){
System.out.println("请输入账号");
String s1 = sc.nextLine();
System.out.println("请输入密码");
String s2 = sc.nextLine();
Demo_User d2 = new Demo_User(s1,s2);
list.add(d2);
if(list.contains(d2)){
System.out.println("登录成功");
break;
}else{
break;
}
}
}
}
}
|
|