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

Jake Nagle
Jake Nagle
2,942 Points

Stumped on a challenge

My code isn't returning any errors, it just isn't returning the correct values. When given the last name "zimmerman", it doesn't return 2 as it should and I can't figure out why. It does, however, seem to work with the first half of the alphabet. Any help is appreciated, thanks!

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

}

Disregard this comment, see answer below :)

1 Answer

Sorry, I meant to post this as an answer instead of a comment and it doesn't look like you can delete comments (I guess I haven't had enough coffee yet): The problem might be that you're checking for a value greater than a lowercase 'm', but the ASCII values for uppercase letters are actually lower than the values for lowercase letters. Try setting the letter stored in the initial variable to lowercase before you compare (or setting it to uppercase and comparing the value to 'M').

Jake Nagle
Jake Nagle
2,942 Points

Thank you so much for clearing this up Kathryn! Not being able to figure out the problem was driving me crazy.