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 trialkevin nisay
1,159 PointsBummer! i entered Anderson and expected to get back line 1 as A comes before M. im not able to understand what is wrong
guys i need your help my brain is bleeding now,
public class ConferenceRegistrationAssistant {
String firstLine; String secondLine;
public int getLineFor(String lastName) {
int line = 0; if (lastName.matches("[A-M?]")){ firstLine += lastName; } else { secondLine += lastName; } return line; }
}
2 Answers
Raquel Smith
10,683 Pointspublic class ConferenceRegistrationAssistant {
String firstLine;
String secondLine;
public int getLineFor(String lastName) {
int line = 0;
if (lastName.matches("[A-M?]")){
firstLine += lastName;
} else {
secondLine += lastName;
}
return line;
}
}
Alright, above I've put your formatted code since it'll be a LOT easier to read. To add formatted code in the future, add three fancy apostrophes (on the tilde key above the tab key on your keyboard) before and after your code.
It looks like you are trying to add the last name to the first line. However, you are just supposed to return an int
that says which line the person is supposed to go to. After that, you need to compare the first letter of last name (hint charAt
) to the character M. If it is less than or equal to M, you will return 1. Otherwise, you will return 2. So...
public int getLineFor(String lastName) {
if (first letter of last name <= 'M') {
return 1;
} else {
return 2;
}
}
The code as written above will obviously not work, but it's a jumping off point for you. Fill in what you need.
Mallikarjuna A S
Python Web Development Techdegree Student 7,017 PointsIt is Specified in you can use character Comparison
Here I go
public int getLineFor(String lastName) {
int line = 0;
if (lastname.charAt(0) > 'M')
{
line++;
} else {
line = line + 2;
}
return line;
}