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 trialkalyada leosrisook
Courses Plus Student 17,855 PointsCan anyone help me getting start on this getLineFor challenge?
I'm puzzled with this challenge and don't know where to start. Can anyone help me ?
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;
return line;
}
}
1 Answer
Simon Coates
28,694 Pointstake a look at
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 */
char firstChar = lastName.charAt(0);
int line;
if(firstChar <= 'M') line = 1;
else {
line = 2; //or return 2 to exit immediately.
}
return line;
}
}
The first task is isolating the first letter. To do this, look at string documentation to find the getChar method. Once you have a character, you can do the comparison. (may help to know about the numerical values for characters are ordered )