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 trialsamuel zaffran
24,815 PointsCan't Succeed That Challenge
Hi, I'm trying for almost couple of hours now to solve the challenge, but i don't understand how to do it. Can someone explain to me please ? I'm driving nuts !!
2 Answers
Grigorij Schleifer
10,365 PointsHey samuel,
try this code! I commended it a little:
public class ConferenceRegistrationAssistant {
public int getLineFor(String lastName) {
int line = 0;
if(lastName.charAt(0) > 'M') {
// the getLineFor method takes a String "lastName" as argument
// Strings are concatenations of characters and they can be count from 0
// you can use the charAt() method to compare the char at the place 0 inside String "lastName"
// with a single character of your interest
// here we write a condition: if char at position 0 of the "lastName" is greater then character 'M'
// the line is 2
return line = 2;
// return int 2
} else
// everething is under 'M'
// line is 1
return line = 1;
// return int 1
}
}
Does it make sense?
Grigorij
karson Adam
32,623 PointscharAt(int index) returns the character located at the String's specified index. The string indexes start from zero. eg:
/* 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) <= 'M'){
// if last name is less than "m"
}else{
// if is greater
}
samuel zaffran
24,815 PointsThank you very much !!
Grigorij Schleifer
10,365 PointsYou are welcome :)
samuel zaffran
24,815 Pointssamuel zaffran
24,815 PointsThank's a lot, very helpful !!