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

No errors but incorrect logic.

Attached is my code. The output for my code - Bummer! I entered Zimmerman and expected to get back line 2 as Z comes after M. Help me with 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 line1 = 0;
    int line2 = 0;
    if(lastName.charAt(0) <= 'M') {
      return line1;
    } else {
      return line2;



2 Answers


I replied to a different question you raised on the same point.

I think the issue is that you are declaring two variables to do the job that one can do and then you're not assigning the appropriate value to it.

You're doing everything right but are just slightly over-complicating the challenge.

There are two lines; they are mutually exclusive so one variable can cover that task. So, test the first letter of the name then either assign the integer 1 or 2 to the single variable and return that from the function. Job done!

You don't need to increment - just assign the value to the variable; line = 1;, for example.

So, one variable called line and assign either 1 or 2 to it in each side of your if conditional, then return line after the conditional has done.

I posted my code in the other post


That clears things up. Like you said using one vairable and assigning it values turns out to be simplest way to do it. Thanks Tomasz and Steve!