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

Can somebody please give me some guidance on the line numbers objective? I'm completely stumped.

Everything I've tried gives me a long list of errors. I just need to be pointed in the right direction.

Can you post a link to the challenge or video?

2 Answers

You are making it more complex than need be. You can eliminate the additional variables and use lastName.charAt(0) in your comparison in the if statement .

if (lastName.charAt(0) < 'N') {
    lineNumber = 1;
}
else {
    lineNumber = 2;
}

That makes perfect sense. Thanks a lot!

Some hints:

  • You will want to use an if else statement in assigning lineNumber a value of 1 or 2
  • You can use the charAt(0) method to get the first character of lastName
  • You can use character < 'N' to check if a character is between A and M.

This is the code I have generated so far:

int first = 1;
int second = 2;
String line1 < 'N';
char letter = lastName.charAt(0);
boolean manage = line1.indexOf(letter) != -1;
if (manage) {
  lineNumber = first;
} else {
  lineNumber = second;
} 
return lineNumber

}