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 trialChris Vukin
17,787 Pointspublic boolean needed?
this course is giving me lots of issues, it would be great if the concepts could be repeated 3x or more in various code challenges to get the info to stick. anyway, with this one I'm not sure how to form the syntax. I believe what is being asked is to compare the lastname.charAt(0) to separate into two lines. it would seem that lastname.charAt(0) > M = line2 else lastname.charAt(0) = line1 shouldn't be that difficult. unfortunately the syntax escapes me even when comparing to the code we wrote along with the vid for this stage. also, why is there an int line = 0 prepopulated in the code?
any assistance is appreciated as I've spent the last 30min trying different code with no success.
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 */
lastname.charAt(0)
int line = 0;
return line;
}
}
6 Answers
Chris Vukin
17,787 PointsOh snap! thanks Craig :) I'll make it thru yet. Is there a good resource that labels the individual parts of a method structure? I'm referencing the Java docs here: http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html I'm a pretty visual learner though, something with the method structure and declarations/calls inside with a nice picture diagram would be sweet..
Thanks again.
Craig Dennis
Treehouse TeacherThis is looking for using the if and else syntax we learned earlier and this is covering it again. The goal is to set the line variable which was provided to either 1 or 2, depending on where the first letter of the last name lies.
Does that help clear up what is being asked for?
Chris Vukin
17,787 Pointsnot so much. if/else seems like a great choice for making this comparison and I think I'm comfortable with that syntax. please find below my proposed solution, with the error's thrown it looks like I need to convert lastName into a boolean value in order to get this to pass.
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) {
lastName.charAt(0) > 'M';
return line + 2;
} else {
return line + 1;
}
}
Alternatively tried:
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') {
return line + 2;
} else {
return line + 1;
}
}
which gets me down to only one error but still no go.
Craig Dennis
Treehouse TeacherSecond go is super close. Try assigning line either 1 or 2 in your if/else and leave the single return.
If that doesn't work, share your error.
You are super close, logic looks great in the second one!
(Truthy checks don't work in Java, that's what's up with the first one)
Craig Dennis
Treehouse TeacherOooh...you are missing a trailing }
Chetram Chinapana
1,793 PointsChris. I was having a problem and I check out another user and I tweaked my code. Mine look something like this.
int line = 0; char lineSort=lastName.charAt(0); if (lineSort < 'M'){ line = 1; } else { line =2; } return line;
This worked for me. Try it out and double check your brackets.
Chris Vukin
17,787 PointsThanks Chetram! I was able to solve with Craig's advice.
Appreciate your reply.