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
Madison Keller
2,252 PointsJava Objects, Delivering the MVP Stage 3 Challenge Task 1
I'm having trouble with the code in this. Here is my code:
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) < 'n') {
line += 1;
} else {
line += 2;
}
return line;
}
It looks right to me, and I don't get any syntax errors, except when it runs I get "I entered Zimmerman and expected to get back line 2 as Z comes after M".
What am I doing wrong? It looks to me like this should return 2 for a name starting with Z?
1 Answer
Heather Spence
5,356 PointsYours looks good except I assume the last name comes in capitalized, so you should compare with 'N' rather than 'n'.
Madison Keller
2,252 PointsThat was the problem, Thanks!
Quick question about java. I used N because I assumed if you A - M to go to line 1, that any line where the first letter is less than N is ok. so in Java if I have N < N, would that be true or false?
Heather Spence
5,356 PointsHeather Spence
5,356 PointsMadison,
N<N would be false, because it is saying "Is N less than N?".Another way to put it would be:lastName <=M