我正在尝试创建UserAccount和UserAccountDriver类,以检查用户名和密码是否正确。我无法找到如何修复我的checkpassword方法。当我调用检查密码方法时,它只能显示一条消息。
我试图切换return语句,并在Driver类的'if'语句中更改参数。
UserAccountDriver类
System.out.println("Username: ");
String username = sc.nextLine();
//set username and password
System.out.println("Password");
String password = sc.nextLine();
UserAccount newUser1 = new UserAccount("Austin", password);
//UserAccount newUser2 = new UserAccount(username2, password2);
if (newUser1.checkPassword(password)) {
System.out.println("You are logged in");
}// end if
else {
System.out.println("The username and password are incorrect");
UserAccount
private String username = "Austin"; //creating the
private String password = "Fame";
private Boolean active;
public UserAccount(String user, String pass) { //User Account method
this.username = user;
this.password = pass;
}
public boolean checkPassword(String password) {
if (this.password == password) {
return false;
}// end if
else {
return true;
} // end else
} // end method
我希望当我输入正确的用户名和密码时,它会告诉我它是正确的;而当我输入错误的用户名和密码时,它将告诉我其错误。