Knowee
Questions
Features
Study Tools

package test3;public class Test3 { // DO NOT write a main method public static String getUserName (String firstName, String lastName) { // return the user name as LastName, FirstName e.g. Smith, John } … } }

Question

package test3;public class Test3 { // DO NOT write a main method public static String getUserName (String firstName, String lastName) { // return the user name as LastName, FirstName e.g. Smith, John } … } }

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is the implementation of the getUserName method in the Test3 class:

package test3;

public class Test3 {
    // DO NOT write a main method
    public static String getUserName (String firstName, String lastName) {
        // return the user name as LastName, FirstName e.g. Smith, John
        return lastName + ", " + firstName;
    }
    //...
}

This method takes two parameters, firstName and lastName, and returns a String in the format "LastName, FirstName". The + operator is used to concatenate the strings.

This problem has been solved

Similar Questions

Given the following set of classes, what needs to be fixed to make the program produce the output Name: Java?public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }}class CustomerTest { public static void main(String[] args) { Customer c1 = new Customer("user","pass"); c1.setUserName("Java"); outputName(); } public static void outputName(){ System.out.println("Name: " + c1.getUserName()); }} a.)The c1 should be returned as a return value from outputName().b.)The c1 should be passed into the outputName() method as a parameter.c.)The instance c1 is not in scope in the method outputName(). The instance c1 needs to be declared in outputName()d.)The instance c1 is not in scope in the method outputName(). The c1 should be globally in CustomerTest to be accessed in the outputName() method.

Generate User NameFix getUserName so that it returns the user’s name as "LastName, FirstName" (without the quotes).Capitalise the first letter of the first and last namesIf the lastname is null, just return firstname without a commae.g. "John" "Smith" should return "Smith, John"

For t5he above code please correct it as Generate User Name Fix getUserName so that it returns the user’s name as "LastName, FirstName" (without the quotes). Capitalise the first letter of the first and last names If the lastname is null, just return firstname without a comma e.g. "John" "Smith" should return "Smith, John"

Given the following set of classes, what would need to be fixed to make the program work?public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }} class CustomerTest { public static void main(String[] args) { Customer testAcct = new Customer("user","pass"); testAcct.setPassword("Java"); resetAcct(); } public static void resetAcct(Customer acct){ acct.setPassword(""); acct.setUserName(""); }}The instance testAcct is not in scope in the method resetAcct(). The instance testAcct needs to be declared in resetAcct()The testAcct should be returned as a return value from resetAcct().The testAcct should be declared at the class level to be accessed in the resetAcct() method.The testAcct should be passed into the resetAcct() method as a parameter.

Given the following set of classes:public class Customer { private String userName; private String password; public Customer(String userName, String password) { this.userName = userName; this.password = password; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; }} class CustomerTest { public static void main(String[] args) { Customer testAcct = new Customer("user","pass"); testAcct.setPassword("Java"); System.out.println(testAcct.toString()); }}What does the toString() method need to look like to result in the following output:UserName: userPassword: Javaa.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return state;}b.)public String toString() { String state = "UserName: " + userName + "\n"; state += "Password: " + password + "\n"; return password;}c.)public String toString() { String state = "UserName: " + userName + "\n"; state = "Password: " + password + "\n"; return state;}d.)public String toString() { String state = "username: " + userName + "\n"; state += "password: " + password + "\n"; return state;}

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.