Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Question about the getLineNumberFor exercise.

My code keeps receiving the error: "Hmmm, I entered "Nelson" for the lastName and expected line number 2 to be returned, but instead it was 1" Or when tweaked it give an error with the last name "Mandela" being placed in line 2. I have been at this for longer than I feel comfortable admitting. Any help would be greatly appreciated.

public class ConferenceRegistrationAssistant {


  public int getLineNumberFor(String lastName) {
    int lineNumber = 0; 
    if (lastName.charAt(0) <=  'm') 
      lineNumber = 1;
    else 
      lineNumber = 2;

    return lineNumber;
  }

}

1 Answer

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Keith Wilson

Glad to see you came up and figured the logic, the only correction is using m instead of using the Uppercase M.

Please see my code below and let me if it works.

public int getLineNumberFor(String lastName) {
    int lineNumber = 0;

    char letter = lastName.charAt(0);
     if (letter <= 'M') {

     lineNumber = 1;
     }

    else{
    lineNumber = 2;
    }
    return lineNumber;
  }

Happy coding

Well, now I just feel silly. Thank you very much for your help!