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 trialMateusz Hyla
11,210 PointsI don't know how to code that in Java Objects Chapter Exercise
Hello
I am begginer in Java and I do not know how to code this exercise. Maybe it is because I do not understand clearly what it is about. I know English very well but sometimes I don't get what is idea of someone who is giving this exercise and what to do.
If someone could help me with it it would be great.
Thanks in advance :-).
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 line1 = 0;
int line2 = 0;
if(lastName.charAt(0) <= 'M'){
line1 += lastName.charAt(0);
return line1;
}
else{
line2 += lastName.charAt(0);
return line2;
}
}
}
2 Answers
Jeremy Hill
29,567 PointsIt should look like this:
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) < 'N')
line = 1;
else
line = 2;
return line;
}
}
Cindy Lea
Courses Plus Student 6,497 PointsIn this assignment they are not requiring to call function.
Martin Smith
Courses Plus Student 467 PointsMartin Smith
Courses Plus Student 467 PointsSo you're returning an int but in your code you're trying to add a string(char) to line1 or line2?
From what i'm seeing is that you're suppose to just add 1 person to the end of the line and return the line so
might work?