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 trialCharlie Gallentine
934 PointsI'm not sure where to start. Could someone please walk me through this challenge?
I've been working on this for a while, but I am utterly lost. Any help would be greatly appreciated! Thank you!
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;
}
}
2 Answers
anil rahman
7,786 PointsCould also do this extra check so charlie might understand it better seen as though question says between A and M
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;
//if between A and M (the charAt(0) means grab the first letter of my last name)
if(lastName.charAt(0) >= 'A' && lastName.charAt(0) <= 'M'){
line = 1;
}
else{
line = 2;
}
return line;
}
}
Charlie Gallentine
934 PointsThank you! This helps a ton!
Grigorij Schleifer
10,365 PointsHi Charlie,
public int getLineFor(String lastName) {
// the line variable is needed to store the line value and return it later on
int line = 0;
if (lastName.charAt(0) < 'M') {
// inside the parenthesis get the first character from the argument using the charAt method
// proof it against 'M', so every first char that is less then M will go into line 1
line = 1;
} else {
// if the first character of the name is greater then M -> line 2 will be returned
line = 2;
}
return line;
// return the value in dependance of the first character
}
Makes sense?
Grigorij
Gabriel E
8,916 PointsI thought we might kind of want to help him with a walk-through step-by-step, instead of just posting the code, but as long as he get's it, this works as well! :-D
Charlie Gallentine
934 PointsThank you! That actually makes far more sense than what I was thinking!
Charlie Gallentine
934 PointsThanks! That makes more sense! The comments really help!
Gabriel E
8,916 PointsGabriel E
8,916 PointsHi Charlie, Could you please provide a link to the direct challenge? I think we could better help you then.