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

Emanuel Vasconcelos
Emanuel Vasconcelos
4,248 Points

How am I supposed to send someone to line 1 or line 2?

I undesrtand the condition and everything but how am I supposed to send someone to line 1 or 2. Do I need to declare other variables for those or what?

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {
     public String line1;
    public String line2;
  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 */

    if (lastName.charAt(0) >'M') {
      line2 = lastName;
      return line2;
    } else {
      line1 = lastName;
      return line1;
    }


}

1 Answer

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Hey Emanuel,

I think you might be overthinking the code challenge.

You don't need to declare line1 and line2 as class fields because you're not creating a class constructor, getLineFor() is a method.

Once you delete the class fields, line1 and line2, you can simplify your method to:

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

}

Does that help you? Let me know if you have any more questions.

Emanuel Vasconcelos
Emanuel Vasconcelos
4,248 Points

Oh, yes. I can see now. I was a little bit confused with the line variable and with the instruction of sending someone there. I thought I needed to declare other variables for line 1 and line 2. Thanks a lot, I simplified it and it now works.