import java.io.*;
import java.util.*;
class Test
{
public static void main (String[] args)
{
ImpUserFuction iuf = new ImpUserFuction();
System.out.println("1:登录");
System.out.println("2:注册");
System.out.println("输入你的选择:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
switch(s)
{
case "1":
{
System.out.println("输你的用户名:");
String name = sc.nextLine();
System.out.println("输你的密码:");
String pass = sc.nextLine();
boolean b = iuf.userLogin(name,pass);
if(b)
System.out.println("登陆成功");
else
System.out.println("用户名或密码错误:");
break;
}
case "2":
{
System.out.println("输你想要的用户名:");
String name = sc.nextLine();
System.out.println("输你想要的密码:");
String pass = sc.nextLine();
User user = new User(name,pass);
iuf.userRegist(user);
}
case"3":
default:
System.out.println("小伙子按规矩来:");
}
}
}
class User
{
private String userName;
private String userPossword;
public User()
{
}
public User(String userName,String userPossword)
{
this.userName = userName;
this.userPossword = userPossword;
}
public String getUserName()
{
return userName;
}
public String getUserPossword()
{
return userPossword;
}
}
interface UserFuction
{
public abstract boolean userLogin(String userName,String userPossword);
public abstract void userRegist(User user);
}
class ImpUserFuction implements UserFuction
{
static ArrayList<User> al = new ArrayList<User>();
public boolean userLogin(String userName,String userPossword)
{
boolean flag = false;
for(User user:al)
{
if(user.getUserName().equals(userName) && user.getUserPossword().equals(userPossword))
{
flag = true;
}
}
return flag;
}
public void userRegist(User usr)
{
al.add(usr);
}
}
|
|