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 trialMohammad hesam Ebrahiminejad
892 Pointsi dont which part im missing?
i think im missing somthing .can sombody help what is it
public class ConferenceRegistrationAssistant {
public int getLineFor(String lastName) {
lastName.charAt(0) = FirstChar;
if(FirstChar < "M"){
String line1 =line1 + " ," + lastName;
}else{
String line2 =line2 + " ," + 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
jcorum
71,830 PointsFirst, you cannot assign a value to charAt(0):
lastName.charAt(0) = FirstChar;
lastName.charAt(0) will return a value, viz., a char, which you could assign to a char variable. But in this challenge you don't need to assign it to anything.
Second, your function is written to return an int, as it has int as the return type, but you are creating two Strings, and then you ignore them, but return line, which hasn't yet been declared.
public int getLineFor(String lastName) {
. . .
String line1 =line1 + " ," + lastName;
. . .
String line2 =line2 + " ," + lastName;
. . .
return line;
Third, your code should be between these two lines, not above them, as you need to use the line variable, and so need to have it declared:
int line = 0;
return line;
Also, you need to see if the char returned by lastName.charAt(0) is less than 'M', and if it is re-initialize line to 1 and if not to 2.
So, with these changes it should look something like this:
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; //line gets declared and initialized to 0
if (lastName.charAt(0) < 'M') { //you get the first char in lastName and see if it is less than 'M'
line = 1; //if less reinitialize line to 1
} else {
line = 2; //otherwise reinitialize line to 2
}
return line;
}