public class Test {
public static void main(String[] args) {
ArrayList<user> a = new ArrayList<user>();
user u=new user("a","1234");
user u1=new user("b","1234");
a.add(u);
a.add(u1);
while (true){
System.out.println("=========================");
System.out.println("0.用户 1.登陆 2.注册 3.退出");
System.out.println("=========================");
Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
switch (n){
case 0 :
System.out.println("----用户信息----");
for (user user : a) {
System.out.println(user.getUsername()+": "+user.getPassword());
}
break;
case 1 :
System.out.println("----登陆----");
System.out.println("请输入用户名");
String name=new Scanner(System.in).next();
System.out.println("请输入密码");
String password= new Scanner(System.in).next();
denglu(a,name,password);
break;
case 2 :
System.out.println("-----注册----");
System.out.println("请设置用户名");
String name1=new Scanner(System.in).next();
System.out.println("请设置密码");
String password1= new Scanner(System.in).next();
zhuche(a,name1,password1);
break;
case 3 :
System.out.println("您已退出");
System.exit(0);
break;
default:
System.out.println("无此选项");
break;
}
}
}
public static void denglu(ArrayList<user> a,String name,String password){
for (user i : a) {
if(i.getUsername().equals(name) && i.getPassword().equals(password)){
System.out.println("登陆成功");
return;
}
System.out.println("用户名或密码错误,请重新输入");
}
}
public static void zhuche(ArrayList<user> a,String name,String password){
for (user i : a) {
if(! i.getUsername().equals(name)){
System.out.println("注册成功!");
user u=new user(name,password);
a.add(u);
return;
}
System.out.println("用户名或密码错误,请重新输入");
}