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

Noah Cox
Noah Cox
964 Points

How does it want me to make a line 1 or 2?

Here's my code, it says it enters "Zimmerman" but doesn't get line 2 on the preview, the instructions don't seem very clear to me... Could someone clarify what "send them to line 2" really means?

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;
    if (lastName.charAt(0) < 'M'){
    line += 1;
    System.out.println("Line 1");
    } else {
    line+= 1;
    System.out.println("Line 2");
    }
    return line;
  }

}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Noah,

You've pretty much got it, except for one thing. When checking the last name to assign them to a "line", you want to re-assign the value to the int variable line, but you are actually incrementing the value of line by one. Therefore, whichever one of the conditions run, line becomes equal to 1 and therefore assigns both to line # 1.

Instead of line += ... you need to reassign by just using line = ...

I hope that makes sense. So for the if statement, it would be line = 1; and for the else statement, it would be line = 2.

Keep Coding! :dizzy: