public class Test {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入u的用户名:");
String x=sc.next();
//如何输入空的用户名,按回车没用,判定用户名输入为空?
User u = new User(x, "123456");
User u1 = new User("Mike", "123456");
u.yhxx();
u1.yhxx();
System.out.println("===========================");
UserManager um = new UserManager();
um.checkUser(u, u1);
}
}
public class User {
private String user;
private String password;
public void yhxx() {
System.out.println("用户名:" + getUser());
System.out.println("密码:" + getPassword());
}
public User(String user, String password) {
this.user = user;
this.password = password;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
public class UserManager {
public String checkUser(User u, User u1) {
if (u.getUser() != null && u1.getPassword() != null) {
if (u.getUser().equals(u1.getUser())) {
System.out.println("用户名一致");
} else {
System.out.println("用户名不一致");
}
} else {
System.out.println("用户名输入为空");
}
return null;
}
}
添加回答
举报
0/150
提交
取消