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 trialMUZ140151 Gilbert Chapara
2,621 Pointscomparing characters
Hi guys am trying to run this code but its giving me a bummer and unable to show syntax errors where am i wrong
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 letter = lastName.charAt(0);
if(letter > 'M'){
line = 1;
}
if('M' < letter){
line = 2;
}
return line;
}
}
1 Answer
Stephen Bone
12,359 PointsHi MUZ140151 Chapara
You're close with your answer but you first need to move it inside of the getLineFor method.
As in:
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;
char letter = lastName.charAt(0);
if(letter > 'M'){
line = 1;
}
if('M' < letter){
line = 2;
}
return line;
}
Next you need to look a bit more closely at your if statement logic as it's not quite right and replace them with an if else statement otherwise once you get your if statement logic correct you'll actually receive a message stating your code is correct but change it anyway! :)
Hope it helps but if you need any further assistance let me know.
Stephen
Matthew Stanciu
4,222 PointsMatthew Stanciu
4,222 PointsI'm having the same problem. I checked my code with yours and it seems pretty much the same, apart from a few spaces in the brackets and a different if statement. I also added an else statement.
Stephen Bone
12,359 PointsStephen Bone
12,359 PointsHi Matthew
I think your problem is that char 'M' is going to be true in each case and therefore added to both lines 1 & 2.
This is because your first if statement says if letter is less than or equal to 'M' and the second statement says if letter is greater than or equal to 'M'.
I've made the small change mentioned to your code below:
Once you've corrected the logic of your if statements however you will still receive a message asking you to change them to use the if else statement instead before the task will pass.
EDIT: OK you've changed and updated your comment while I was answering it in its original state :).
The same issue applies although you've now already changed it to an if else statement. However remember that you don't pass a condition to the else statement as this is an if all else fails do this statement.
Hope it helps!
Stephen
Matthew Stanciu
4,222 PointsMatthew Stanciu
4,222 PointsThanks so much for your help! Your solution worked! I was typing else without noticing that I should just be typing another if. Sometimes I do that and it takes me hours to notice.