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

help with code

can someone assist me with this task am not sure how to tackle it

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;
    return line;
  }

}

3 Answers

I personally tackle these challenges by thinking back 2-3 videos and remembering what we learned. I also try to envision what type of loops/decisions I would use.

  1. (If the last name is between A thru M) I know they want an if statement
  2. (send them to line 1) If the first letter is less than M then assign them line 1
  3. (Otherwise send them to line 2) Else, I assign them to line 2

Now you have to decide how to write what goes in the if statement. For this, I would look at any variables they give me, including any that are in the method parameters like "lastName". Since they want me to see if the person's lastName starts with a letter I would do lastName.charAt(0). Now we need to see if the lastName is A thru M (which is easily done by seeing if it is less than N) so lastName.charAt(0) < 'N'.

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 the last name is between A thru M send them to line 1
    if (lastName.charAt(0) < 'N') {
      line = 1;
    } else { 
      //Otherwise send them to line 2
      line = 2;
    }

    return line;
  }
}
Simon Coates
Simon Coates
28,694 Points

Following seems to work

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

Thank you so much for your help.