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 trialDavid Jones
1,681 PointsI keep getting a bummer message that reads: When a "Z" name is entered line 2 is expected but not received.
My boolean getInLine looks like it will be false when lastName.charAt(0) is a number higher in the alphabet (m-z) than "M" because "Z" (26) is <= "M"(13) is false.
Then my if statement says if getInLine is= true then line=1 and if it is false then line=2.
Because in this case is a "Z" name is used boolean should be false and and then the if statement should return line=2. Is my issue with defining the getInLine incorrectly or using the if statement incorrectly? Or is my issue related to what I have in the 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 */
boolean getInLine = lastName.charAt(0) <= 'M';
int line;
if (getInLine = true) {
line =1;
} else {
line = 2;
}
return line;
}
}
2 Answers
Seth Kroger
56,414 PointsThe problem is the line if (getInLine = true)
which is assigning getInLine to true (single vs. double equal signs). It's usually redundant to compare a boolean to true or false in an if statement and just use if (getInLine)
.
RAFAEL LOUSTAUNAU
1,170 PointsSimpler to do this code, because method returns int.
char a_char = text.charAt(0);
if ( a<='A' && a<='M'){ // the greater the letter the higher the value Z being the biggest value line=0; }else{ line=1; } return line;
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherNice eyes Seth Kroger !!!
Seth Kroger
56,414 PointsSeth Kroger
56,414 PointsThanks! :)