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 trialSohaib Rashid
627 PointsHaving Trouble with this task, if anyone can help that would be great! Happy Coding!
The Task is :I have modeled an assistant for a tech conference. Since there are so many attendees, registration is broken up into two lines. Lines are determined by last name, and they will end up in line 1 or line 2. Please help me fix the getLineFor method.
NEW INFO: chars can be compared using the > and < symbols. For instance 'B' > 'A' and 'R' < 'Z'
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;
char firstLetter = lastName.charAt(0);
if (firstLetter > 'N'); {
line = 1;
} else { firstLetter < 'N';
line = 2;
}
}
}
1 Answer
Steve Hunter
57,712 PointsSomething like:
if (firstLetter < 'N') {
line = 1;
} else {
line = 2;
}
You don't need the second conditional test as they are mutually exclusive - if the first is > 'N'
then the second isn't so there's no need to test twice. I also switched the > and < as they were going to the wrong lines.
Then you need to return line
after those lines of code else the code will never run.
Sohaib Rashid
627 PointsAhhh i see my errors now and have learned from your corrections! Thank you for your guidance! Happy Coding!
Andrew Jensen-Battaglia
10,051 PointsAndrew Jensen-Battaglia
10,051 PointsFor starters, you'll want to place the return statement at the end of your function. Also, it looks like the syntax of your conditional statement is incorrect. Conditional statements should look something like the following: