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 trialNathan Pickard
10,950 PointsStumped on challenge
Not sure what to do differently to get the correct output. They ask : "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'Thanks!
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 */
if (lastName.charAt(0) <= 'M') {
System.out.println("Line 1");
} else {
System.out.println("Line 2");
}
int line = 0;
return line;
}
}
2 Answers
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there Nathan!
You're super close on this, just a few very minor things need to changed,
The first thing you want to do is your if statements are set up perfectly, after in the first one since we are checking if lastName.charAt(0) is greater than 'M', if it is than they should go to line 2, not one.
The other thing that needs to be corrected is change your System.out.println() statements to changing the value of your line variable, also be sure to that your int line = 0; declaration is at the top, so that both loops have an access to it.
It should look something like below
public class ConferenceRegistrationAssistant {
public int getLineFor(String lastName) {
int line = 0;
/* If the last name is between A thru M send them to line 1
Otherwise send them to line 2 */
if (lastName.charAt(0) >= 'M') {
line = 2;
} else {
line = 1;
}
return line;
}
}
Thanks, don't hesitate to let me know if this doesn't help, and I'll look at what I can explain better.
Nathan Pickard
10,950 PointsI appreciate the help Rob! I changed the '>' to '<' and adjusted the 'int line = 0;' statement to the top. It's encouraging when you have people willing to provide such great help!
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsNo problem!
Glad to hear I could help, don't ever hesitate to venture to forums, tons of knowledgeable people willing to help.
David GΓ³mez
4,389 PointsDavid GΓ³mez
4,389 PointsThanks for you two, I was having problems in this same challenge. I hadn't figured out I needed to add ".charAt(0)", then it worked. Instead of >= 'M' I wrote <'N'... less keys to press XD
Thanks!
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey David glad to hear it helped!