user1738642 user1738642 - 1 month ago 26
Java Question

Code wars: Sign up issue

Im very new to programming and I recently tried to sign up to code wars. It shows a number of problems, presumably before letting someone sign up.

At the minute I'm stuck on this one:

public class Person{
String name;

public Person(String personName){
name = personName;
}

public String greet(String yourName){
return String.format("Hi %s, my name is %s", yourName, name);
}
}


Stating Correct this code, so that the greet function returns the expected value.

I can't for the life of me figure out what the problem is. I tried inputing the code into eclipse and there are no errors, so I'm not entirely sure what is required

Answer

I think it wants you to greet someone else.

public class Person{
String name;

public Person(String personName){
    name = personName;
}

public String greet(String yourName){
    return String.format("Hi %s, my name is %s", name, yourName);
}
}

So that the output is

Hi (person), my name is (whatever your name is)

Comments