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

not sure where to go with this

feel like I'm missing something here, but can't figure out how to implement it

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {
    char firstLetter = lastName.charAt(0);
    if(firstLetter<'M'){
      return line;
    }else{
      return line2;
    }


    int line = 1;
    int line2 = 2;
    return line;
  }

}

1 Answer

Logan R
Logan R
22,989 Points

You're doing good, but there are a few flaws.

First off:

if(firstLetter<'M'){
    return line;

If the letter is A-N, it will return line, but the problem is you want letters A-M.

Also:

public int getLineFor()

If you have a look at what our function is returning, it is an integer. This means that the return will be return 1; or return 2;.

We could also return a variable that is an integer.

int line = 1;
int line2 = 2;

The problem with your code is that those two variables come after your if statements and so therefore are not defined and will produce an error. You need to move them above your if statements.

public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {
    int line = 1;
    int line2 = 2;

    // If statements with the returns

    // The 3rd and last return should be removed as it will never be reached (and will produce an error).
  }

}

Make those few adjustments and you should be in business :)