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 Java Objects Creating the MVP Conference Registration Assistant

Does my code solve the problem, If so why is the complier not letting it through ?, otherwise what have I done wrong ?

  • Been doing basic Java for a year
ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {
  public int getLineNumberFor(String lastName) {
    int lineNumber = 0;
    if  ( 'A' <= lastName.charAt(0) =< 'M') 
    {lineNumber = 1;
    }
    else if ('N' <= lastName.charAt(0) =< 'Z') 
    { lineNumber = 2;
    }
    return lineNumber;
  }

}

1 Answer

Hi there,

You can't use tests like you have done:

if  ( 'A' <= lastName.charAt(0) =< 'M') 

If you want to do two tests like this, you need to be explicit about it and check each condition completely:

if  (lastName.charAt(0) >= 'A' && lastName.charAt(0) <= 'M') 

Also, this isn't valid: =<. It is the other way around, <=.

Now to the challenge. Your method is exactly right. You're testing the first character to see which line the person should be placed in. Correct. There's two tests that aren't required - the challenge assumes the names are correctly input, i.e. they start with a letter. So, there's no need to test for >= 'A' or <= 'Z' - all letters fit those tests!

And you only need to do one test. You just need to know if the first character is <= 'M'. That test is exclusive - the only other option is that the letter is > 'M' so there's no need to check if it is - that's a given! There's also no need for the lineNumber variable, although you could say the code is more readable with it in there? I think it is simple enough to omit it.

  public int getLineNumberFor(String lastName) {
    //int lineNumber = 0;
    if(lastName.charAt(0) <= 'M'){
      return 1;
    }
    return 2;
  }

Make sense?

Steve.