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

Dylan Carter
Dylan Carter
4,780 Points

help with my code for "creating characters" challenge

this is my code, its not getting any syntax errors but its still saying its not right, any help?

public class ConferenceRegistrationAssistant { private int lineOne; private int lineTwo;

public int getLineFor(String lastName) { lineOne = 1; lineTwo = 2;
if (lastName.charAt(0) >= 'M') { return lineOne; } else return lineTwo; }

}

1 Answer

Marc Schultz
Marc Schultz
23,356 Points

Your code:

public class ConferenceRegistrationAssistant {

    private int lineOne; // don't use global variables for this purpose
    private int lineTwo;

    public int getLineFor(String lastName) {
        lineOne = 1;
        lineTwo = 2;
        if (lastName.charAt(0) >= 'M') { // why >= ?
            return lineOne; // this should be line 2
        } else  // rounded bracket is missing
            return lineTwo; // this should be line 1
        }
    // rounded bracket is missing again
}

The solution:

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 = 2;
    } else {
      line = 1;
    }
    return line;
  }

}
Dylan Carter
Dylan Carter
4,780 Points

thank you I ended up figuring it they just wanted line as the variable and to change its value I thought they meant two variables for each line. and I also fixed my syntax issues. and I made it < m instead of > which would explain my variables

but with > (or <) than m, what if the char was M? that's why I was using =<