Nick W.

asked • 11/01/21

Error in my java class NEED HELP

public class User

{

private String firstName;

private String lastName;

private LoginCredentials loginCredentials;


/**

*

*/

public User(String firstName, String lastName)

{

this.firstName = firstName;

this.lastName = lastName;


String userName = Character.toLowerCase(firstName.charAt(0)) + lastName.toLowerCase();

String password = firstName.charAt(0) + lastName + "@123";


loginCredentials = new LoginCredentials(userName, password);

}


/**

*

*/

public String toString()

{

return "User login \nFirst Name = " + firstName

+ "\nLast Name = " + lastName

+ "\nUser Name = " + loginCredentials.toString();

}


/**

*

*/

public boolean equals(User obj)

{

if(loginCredentials.equals(obj.loginCredentials))

{

return true;

}

else

{

return false;

}

}

//to test the login credientials

/**

*

*/

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.print("Please enter your first name: ");

String input = sc.nextLine();

System.out.print("Please enter your last name: ");

String input2 = sc.nextLine();

System.out.println("____________________________________________");

String firstName_of_user = input;

String lastName_of_user = input2;

User username = new User(firstName_of_user, lastName_of_user );

System.out.println(username);

System.out.println("____________________________________________");

User password = new User( username + "@123");

System.out.print("Generated password is: " + password);

}

}


ERROR: java.lang.String found: java.lang.String,char reason: actual and formal argument lists differ in length

1 Expert Answer

By:

Preston Z. answered • 11/01/21

Tutor
New to Wyzant

Recent Computer Science Grad

Nick W.

Should I add the code in public static to public User(String firstName. String lastName)
Report

11/01/21

Nick W.

If i do "String password = firstName.charAt(0) + lastName + "@123";" it gives the erro that i can use this in a static context
Report

11/01/21

Nick W.

im confused
Report

11/01/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.