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 (Retired) Creating the MVP Comparing Characters

Jarren Bess
Jarren Bess
985 Points

ConferenceRegistrationAssistant

what am i doing wrong here?

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {
    /* If the last name is between A thru M send them to line 1
       Otherwise send them to line 2 */
    int line = 0;
    char letter1 = 'a';
    char letter2 = 'm';
    if (letter1 > letter2) {
      line = 2;
    } 
    if (letter1 < letter2) {
      line = 1;
    }
    return line;
  }

}

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Jarren,

in your approach you are comparing the char 'a' with the char 'm'.

a is greater then m and the result of the first if statement is always true + the line 2 is returned because both chars are hardcoded. This is not what this tricky challenge wants you to do :smiley:

For this challenge the examination of the first character of the argument String lastName is needed. If this first char on position 0 of the String is less then M... line 1 should be returned, else line 2 will be returned. You can use the charAt() on the argument to look at the first character inside the String.

You chan use this code:

if(lastName.charAt(0) <= 'M') {
    line = 1;
} else {
    line = 2
}
return line;
}

I hope this helps. Don´t hesitate to ask again if something is not fully clear.

Grigorij

Jarren Bess
Jarren Bess
985 Points

Thanks that helped :)