public class UserDaoImpl implements UserDao {
private static ArrayList<User> arrayList = new ArrayList<User>();
@Override
public boolean isLogin(String username, String password) {
boolean flag = false;
/*
* for (int i = 0; i < arrayList.size(); i++) { User user =
* arrayList.get(i); if (!arrayList.isEmpty()) { if
* (user.getUsername()==username && user.getPassword()==password) { flag
* = true; break; } } }
*/
for (User u : arrayList) {
User user = u;
if ((user.getUsername().equals(username))
&& (user.getPassword().equals(password))) {
flag = true;
break;
}
}
return flag;
}
@Override
public void register(User user) {
arrayList.add(user);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("欢迎来到itcast!");
System.out.println("1、登录");
System.out.println("2、注册");
System.out.println("3、退出");
System.out.println("请选择:");
String s = sc.nextLine();
switch (s) {
case "1":
System.out.println("欢迎来到登录界面!");
for (int i = 0; i < 3; i++) {
System.out.println("请输入用户名:");
String username = sc.nextLine();
System.out.println("请输入密码:");
String password = sc.nextLine();
UserDaoImpl ud = new UserDaoImpl();
if (ud.isLogin(username, password)) {
System.out.println("登陆成功");
System.exit(0);
}
if (i == 2) {
System.out.println("你的账号已经冻结,请于周丹玲联系!");
System.exit(0);