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

Mike Omaliko
Mike Omaliko
3,995 Points

I have used the "Preview" on my code and no errors, but for some reason I keep getting "Bummer"

Help!

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant 
{
  public int line;

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

}

I tried testing what you wrote, but I didn't get any errors and since "Bummer" isn't the most helpful message, I'm not sure what to suggest.

2 Answers

I see a small problem with your code that can sometimes cause compiler errors.
The problem is that in the case that none of the conditions are true, the variable line is never instantiated. An easy fix to this would be to change your else if statement to just an else. Or, initializing line to -1 before the conditional statement, so that regardless of the result there is a value to be returned.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Can you define line in the method please? I think make that line a member variable is breaking things deep in how I am testing this code challenge.

Just a style thing, but do you need the second if, wouldn't an else just catch everything....else?

Sorry for the confusion!