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

Wilson Chan
Wilson Chan
5,886 Points

Missing return Statement

Anyone can help to solve this?? i have stuck here for a long time nw....i tried using eclipse to solve it but runs well ..

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 line1 = 0,line2=0;
    char getName = lastName.charAt(0);
    if(getName>='A' && getName<='M'){
      return ++line1;
    }
    else if(getName<='Z'&&getName>='N'){
      return ++line2;
    }

  }

}

1 Answer

Hiya,

You're overcomplicating that. The test is mutually exclusive - lastName begins with a letter. Letters are between A and Z; those are safe assumptions. The queue is divided after 'M' or when the initial letter < 'N'. There's no need to check if a letter is >= than to 'A'; they all are; similar to less than or equal to 'Z'. We're not catching typos here.

So you just need to see if the initial letter is less than N, if it is, set line to 1, else set lie to 2. Return the line number.

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

So, the function takes a surname and returns which line the person needs to stand in.

I hope that helps!

Steve.

Wilson Chan
Wilson Chan
5,886 Points

Oh I See!!!! Thanks Steve!!

Haha! I know, it is one of those that leads people down the mega-complicated route very easily! There's only one test needed and the result of that splits into two lines.

Everything is simple when you know the answer! This one catches quite a few people out; which is good - it gets us all thinking.

Steve.

Wilson Chan
Wilson Chan
5,886 Points

yeah!! i was thinking what went wrong...it is actually that simple...hahah still a long way for a rookie like me hahaha