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

Terrence Adderley
PLUS
Terrence Adderley
Courses Plus Student 775 Points

Please help

Can someone help me separate last names into separate lines. Line one is for A - M and line 2 is for O - Z.

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {

    if (charAt(0)) = 'A' < 'm' {
    int line = 1;
    } else {
    int line = 2;
    }
    /* If the last name is between A thru M send them to line 1
       Otherwise send them to line 2 */
    int line = 0;
    return line;
  }

}

2 Answers

Devin Scheu
Devin Scheu
66,191 Points

The code I got for this challenge looks like this:

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

}

If you think my answer was good, feel free to mark it as best answer below, if you need more help in the future from me, you can contact me at devinwscheu@gmail.com.

I think it has to do with your if condition. Try this:

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

What you have seems to be trying if(charAt(0)) which won't work as well as trying to set 'A' equal to 'M' which also won't work, then running the statements in the if.