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

Kevin Khlom
Kevin Khlom
14,369 Points

Stuck on: Java Objects - Conference Registration Assistant Class challenge

I've actually done this a couple of ways and received errors every time. This was my last try with no errors according to the "preview" but the error I'm getting is "I entered Anderson and it does not send me to line 1". I'm kind of lost right now. I even tried:

if(lastName.charAt(0) <= 'a' && lastName.charAt(0) >= 'm'{ line = 1; } else if(lastName.charAt(0) > 'm'{ line = 2; } else { line = 0; }

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

}

1 Answer

Hi Kevin,

First up, we're dealing with capital letters here; I'm not sure if that makes a difference but it would make sense if it does.

Secondly, there's an assumption that the names are entered correctly. Therefore, testing whether a letter is >= 'A' achieves nothing; all letters are >= 'A'!

My code just tests if the initial letter is less than or equal to 'M' and sends the person to the appropriate line.

I hope that makes sense!

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;
  }
}
Kevin Khlom
Kevin Khlom
14,369 Points

That helps out a lot. Thank you so much for your help. I was definitely overthinking this.