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

Return type integer

public class ConferenceRegistrationAssistant { public int line1; public int line2;

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 */ if(lastName.charAt(0) <= 'M') { System.out.println("This guy belongs to line 1"); return line1; } else { System.out.println("This guy belong tos line 2"); return line2; } } }

The question asked to return line 1 or 2 which both are integers. When I run this code it says that it fails for the name anderson. Can you point out my error and suggest a solution.

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {
  public int line1;
  public int line2;

  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 */ 
    if(lastName.charAt(0) <= 'M') {
      System.out.println("This guy belongs to line 1");
      return line1;
      } else {
      System.out.println("This guy belong tos line 2");
      return line2;
      }
  }
}

3 Answers

Hi Wajhiulla,

I did a long answer to this challenge a while ago but can't find it now - try and search, by all means.

However, I think I can see where you're getting frustrated.

Have a try with the following code and let me know if that doesn't make sense to you.

Steve.

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;
  }
}

Your code is mostly correct, but the way you handled the line variable is what's giving you trouble.

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') {
           System.out.println("This guy belongs to line 1");
           return line = 1;
      } else {
           System.out.println("This guy belong tos line 2");
           return line = 2;
      }
  }
}

Thanks for your comments tomasz and steve. I figured out my mistake.