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

Need help with the getLineFor method in stage 3 Creating the MVP exercise

I am having a problem coding the method so it will return a value of line1 or line2

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;
    if ( line = 0 ) {
      'A' < 'M';
    } else {
     line = 2; 
    }
    return line;
  }

}
Ben Morse
Ben Morse
6,068 Points

Just curious on why did you use line = 0 as the condition instead of 'A' > 'M' ??

1 Answer

Line = 0 is only used for initialization. we are only to use line 1 and 2.

int line = 0;
    if ( line = 0 ) {
      'A' < 'M';
    } else {
     line = 2; 

you initialized line as ...int line =0; now when you say if (line =0) what are you saying cause you have already set line as equal to zero above. also there is no need to say 'A' < 'M'. what we need to do is to check if the first letter of the last name is less than N (between A thru M) to put it in line 1. Try the code below and notify me if it helps

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

}