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
Joseph Wasden
20,407 PointsJava Objects - Comparing Characters logic check
This challenge is to sort someone into the correct line based on their last name alphabetical order. As I understand it, This means to write code that checks first character of the lastName String and, if the position 0 char is less than or equal to m, they would be sorted into line 1, otherwise they would be sorted into line 2.
I keep getting an error that the last name Zimmerman doesn't result in line 2, and I can't imagine why. Did I miss something?
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;
//start of my code
if (lastName.charAt(0) <= 'm') {
line = 1;
} else {
line = 2;
}
//end of my code
return line;
}
}
1 Answer
andren
28,558 PointsThe problem is that "m" and "M" are not the same character.
In ASCII (and Unicode) lower case letters come after uppercase letters, "M" is 77 and "m" is 109.
So when you compare the last names (which start with capital letters) to a lower case letter all of the name will be placed in line 1.
Joseph Wasden
20,407 PointsJoseph Wasden
20,407 PointsAhhh.... Thanks! Changed to 'M' and it checks out fine.