将类属性与另一个类进行比较

时间:2014-04-29 18:52:12

标签: java compare instance setter

我上了这堂课。

public class LGMenu {

    String User; 
    String Password;

    public void setUser(String User) {
        this.User = User;
    }


    public void setPassWord(String Password) {
        this.Password = Password;
    }

    public boolean menu(String user,String password){

           Boolean flag = false;

           String input = User + Password;

           String input2 = user + password;


            if(input == input2){
                flag = true;
            }
            return flag;
        }

    }

这节课。

public class Trial{

 String id;
 String password;

public Libreta(){

        if(id ==null){
        setId(reader.read());
        setPassword(reader.read());}


    }

private void setId(String id) {
        this.id = id;

    }

private void setPassword(String password) {
    this.password = password;

}

每次我创建试用版实例时,我都会为该实例永久设置属性ID和密码。我试图创建一种类似登录界面的方法,比较循环中Trial实例的id和密码,并连续设置LGMenu在不同类中的属性,如下所示:

while((n3.menu(user, password)) == false){

                System.out.println("User:");
                User = keyboard.nextLine();
                n3.setUser(User);
                System.out.println("Password:");
                Password = keyboard.nextLine();
                n3.setPassWord(Password);       

        }

但为什么它不起作用?

0 个答案:

没有答案