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 trialMarc Cortez
2,977 PointsIs my approach to this kind of excercise completely off the track??
I'm getting errors like "I entered Zimmerman and expected to be on line 2" or something.
Thanks in advance!
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('A' < 'M') {
line = 1;
return line;
} else {
line = 2;
return line;
}
}
}
2 Answers
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there Marc, you were super close on this looks like just a little logic control flow, which is a one line fix.
When comparing the characters you have it set up to see if
if ('A' < 'M' )
which is always going to be true, so line one will always be returned.
With that being said, change that line.
if (lastName.charAt(0) < 'M')
I did this using your exact code and it passed with flying colors.
Good job! Shoot back if it's still giving you trouble.
Marc Cortez
2,977 PointsHey Rob,
thank you for your great advice! The course didn't tell anything about the charAt() function.
Smart Ganyaupfu
3,129 PointsHey Rob I tried yours but I still get errors. My code is like this below import java.io.Console; 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 */ Console console = System.console(); lastName = console.readLine("enter your last name"); char Name = lastName.charAt(0); if(Name < 'm'){ line = 1; return line; } else{ line = 2; } }
}
Smart Ganyaupfu
3,129 PointsHey Rob I tried yours but I still get errors. My code is like this below import java.io.Console; 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 */ Console console = System.console(); lastName = console.readLine("enter your last name"); char Name = lastName.charAt(0); if(Name < 'm'){ line = 1; return line; } else{ line = 2; } }
}
Smart Ganyaupfu
3,129 PointsSorry buddies, it worked out!! Had to remove some junk and left it simple as in your reference Rob.
All thanks