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 trialBotan Abdullah
Courses Plus Student 2,940 PointsCreating the MVP; returning 1 or 2 according to the last name. Is it correct? or I have a bug?
I am trying this on the java-repl it works, but when I try on the screen I get a runtime error. What should be the problem?
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( lastName.indexOf(0) >= 'A' && lastName.indexOf(0) <= 'M'){
line = 1;
//return line;
}
else{
line = 2;
//return line;
}
return line;
}
}
2 Answers
William Li
Courses Plus Student 26,868 PointsHi, Botan Abdullah , you got it mostly correct, only thing you should change is to replace your indexOf method with charAt, then your code will work perfectly.
Botan Abdullah
Courses Plus Student 2,940 PointsNow I understand the difference, thanks.
Botan Abdullah
Courses Plus Student 2,940 PointsBotan Abdullah
Courses Plus Student 2,940 Pointsthanks a lot , that worked, however shouldn't this ".indexOf()" method work as well? and do the same job?
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 PointsHi, Botan.
No, indexOf and charAt are 2 Java String methods that do almost the exact opposite thing.
Now, you can see, charAt is what you wanna use at this case.