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 trialNeelesh Tewani
1,239 Pointsi am finding problem in this task
// problem in console object because preview said that
Console console = System.console();
String guess = console.readLine("enter the character ?" );
if(guess.indexOf('M')>guess.indexOf('n')){
int line = 0;
return line;
}else{
int line = 1;
return line;
}
}
}
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();
String guess = console.readLine("enter the character ?" );
if(guess.indexOf('M')>guess.indexOf('n')){
int line = 0;
return line;
}else{
int line = 1;
return line;
}
}
}
3 Answers
Steve Hunter
57,712 PointsHi there,
You've got the right idea here.
You want to use the parameter lastName
that is passed in. You're concerned about it's first letter so you can use .charAt(0)
to isolate that.
Once you have the first letter, you need to test if it is 'M' or less. If it is, set the line
variable to be 1. Else, set it to 2.
Then return line
. That could look something like:
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.charAt(0) <= 'M'){
line = 1;
} else {
line = 2;
}
return line;
}
}
I hope that helps.
Steve.
Vedran Brnjetić
6,004 PointsPlease take my answer with a bit of reserve, as I am not a Java developer, and I didn't watch the video before the challenge.
The challenge accepted my following solution:
int line = 0;
if(lastName.charAt(0)<'N'){
line = 1;
}
else
{
line = 2;
}
So by using the charAt() function I took the first char of last name (guessing that people will respect themselves and capitalize their last names), and compared it if it is "smaller" than 'N'.
If anyone finds a better answer, go ahead.
Neelesh Tewani
1,239 Pointsthanku steve for correcting me
Steve Hunter
57,712 PointsNo problem - glad to help! :-)