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

James N
James N
17,864 Points

the compiler errors won't show!

my compiler errors aren't showing, so it won't show what is wrong with my code! CAN SOMEONE PLEASE FIX THE COMPILER ERROR THING!?!?!??!?!?!?!!?!?!??!?!

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 */
    char lastNameFirstLetter = lastName.charAt(0);
    if (lastNameFirstLetter < 'm') {
      line = 0;
    }
    else {
      line = 1;
    }
    int line = 0;
    return line;
  }

}

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

I fixed the compiler error on this one! Sorry 'bout that!

Axel McCode
Axel McCode
13,869 Points

I used the following code for this challenge, I added a few comments. Hope this helps! :)

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 */

    char lastNameFirstLetter = lastName.charAt(0);
    int line = 0; // Declare and Initialize the int variable here before you use it below to make sure it is in scope 

    if (lastNameFirstLetter <= 'M') {   // I added <= so that people with a last name that starts with the letter 'm' would go to line 1
             line = 1; 
    } else {
      line = 2;      // you had "line = 1" here, it should be "line = 2"
    }

    return line;
  }

}
Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You used the int line before declaring it. Also return line 1 or 2, and check against capital 'M'. Other than that code looks great, great job!

I will try and figure out why this code isn't generating a compiler error on the code challenge engine. Sorry for the frustration!

James N
James N
17,864 Points

I already figured out the code challenge, but thanks for the reply anyways!! and also thanks for trying to figure out the bug in the code challenge engine!! I thought that it was line 0 or 1, because you stated in one of this course's videos that 0 comes first. not line 1 or 2.