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

Stuck on Comparing Characters challenge.

I get just 1 syntax error I don't understand. Illegal start of expression with <= ('M'). Am I totally off base or is it a simple fix?

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 */
  boolean getLineFor = lastName.charAt(0) >= ('A') && <= ('M');
    if (getLineFor) {
      return 1;
    } else {
      return 2;
    }
    int line = 0;
    return line;
  }

}

Sorry I've been away a bit.. Thank you for reply. I agree and understand now that the comparison is in the if statement. I used same coding.. if (lastName.charAt(0) >= 'A' && <= 'M') {return 1} else {return 2}, Oddly enough I get the same error with the < being illegal start of expression. I'm moving on hopefully I can figure this out eventually. Your help was much appreciated.

Daniel

Got rid of && to make it work.. if (lastName.charAt(0) <= 'M') { return 1; } else { return 2; }

Thanks again, Daniel

2 Answers

Brandon Adams
Brandon Adams
10,325 Points

My friend, almost everything in that code is very wrong, there are many errors. The comparison logic needs to be in the if statement, you don't need a bool. I think you are overthinking it. Try with pseudo code first. Like:

If (lastName.charAt(0) >= 'A' && <= 'M') {return 1} else if (lastName.charAt(0) >= 'N' && <= 'Z') {return 2};
Michael Zazula
Michael Zazula
555 Points

I know I am a bit late for this but I ran into this myself and I figured it out. You need to put your code after the declaration of the line variable and then change the value of line in your if and else statements. Also you just need to compare the letter to M because we know A is less than M in this case so if the letter is not smaller or equal to M then it must be greater therefore it would be in line 2.

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

}