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

Raiyan Rahman
PLUS
Raiyan Rahman
Courses Plus Student 8,091 Points

Trouble with Stage 3 code challenge (ConferenceRegistrationAssistant) for Java Objects course.

Hello everyone, I've been attempting to complement this code challenge for some time now but so far I've been unsuccessful.

Am I supposed to return a variable called line1 or line2 depending on the first character of the last name?

Or am I supposed return the string "line 1" or "line 2" depending of the character used?

I would really appreciate some help as I've tried everything I could think of.

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;
    int line2 = 0;
    char fString = lastName.charAt(0);
    if(fString > 'M') {
      line2++;
      return line2;
    } else {
      line1++;
      return line1;
    }
  }

}

2 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hello, you want to first set a line variable and initialize it to 0; then throughout your code update the value of line. It'll look something like this. Let me know if I could be any of further help.

int line = 0;

if (fString > 'M') {
 line = 2;
}
else {
line = 1;
}
return line; 
}
Raiyan Rahman
PLUS
Raiyan Rahman
Courses Plus Student 8,091 Points

Ah, now I see. I'm supposed to set the existing 'line' variable to the correct value.

Thank you so much.