Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Comparing Characters

Daniel Schwemmlein
Daniel Schwemmlein
4,960 Points

Stuck at the conference line challenge

Hey guys! I'm supposed to split up people in a queue by their last names here. It says: "Lines are determined by last name, and they will end up in line 1 or line 2. Please help me fix the getLineFor method." I tried a few things but it didn't work. Does anyone have some ideas?

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {
  private String mAnswer;
  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 */
    boolean line = mAnswer.indexOf(lastName);
    if (< 'M') {
      int line = 1;
      return line;
    } else {
      int line = 2;
      return line;
    }

  }

}

1 Answer

Michael Hess
Michael Hess
24,511 Points

Hi Daniel,

You may want to use charAt(0) -- this will get the first letter of the last name. You can use the < operator to compare the first letter of the last name this way.

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;
    if(lastName.charAt(0) < 'M' ){
      line = 1;
    } else{
      line =2;
    }

    return line;
  }

}

Hope this helps! If you're still having issues hit me up!