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 trialtrell story
1,520 PointsI don't know what I am doing....
I may get it later but I am definitely not doing ok for now....
import java.io.Console;
public class ConferenceRegistrationAssistant {
public int line1;
public int line2;
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;
Console console = System.console();
lastName = console.readLine();
char s = lastName.charAt(line);
if ( 'B' > 'A' ){
return line1;
}else {
return line2;
}
}
}
2 Answers
Grigorij Schleifer
10,365 PointsHi trell,
in this challenge you need to put personal data in two lines in dependace of the names first character.
You are right with the if loop, but your condition needs to be mofied and you donΒ΄t need to create a console object because the method getLineFor(String lastName) takes the last name as argument. You can use it for the if condition.
So your condition could say:
IF the first character of our String argument "lastName" is greater (>) then 'M` .... return line 2
Everything else should be less then M
and we can return line 1.
Look at my code suggestion:
I added some comments :)
public class ConferenceRegistrationAssistant {
public int getLineFor(String lastName) {
// the method takes the last name as argument (Erickson)
// and you need the first character of the last name (E)
// so you can use the charAt() method
// inside () of charAt you need to tell the compiler which place of the String you need to look at
int line = 0;
// you need a variable for the line number
// you can change the number of the line, depending on the first character of the "lastName"
if (lastName.charAt(0) > 'M') {
// here you are looking at the first character of the "lastName"
// (0) is the first char, because String lastName is a concatenation of chars
// and this concatenation is 0 based
// the first character (E) is on place (0)
// the second character of the "lastName" variable would be
// lastName.charAt(1) and so on ...
::::::::::::::::::::::::::::::::::
// so the if statement is looking:
// if the char at place 0 (first character) is greater then 'M' then
// line = 2
line = 2;
} else {
// if not greater then `M``
line = 1;
}
return line;
// return the number of the line
}
}
Let me know if you are stuck
Grigorij
trell story
1,520 PointsGregorij,
The line = 0, 1, 2... is where I missed it totally. Thanks man for the break down. It cleared up mental pathways.... "It worked like chewing bubble gum." Later,
trell story
1,520 Pointstrell story
1,520 PointsGregorij,
The line = 0, 1, 2... is where I missed it totally. Thanks man for the break down. It cleared up mental pathways.... "It worked like chewing bubble gum." Later,
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey trell,
I am really glad I could help !
DonΒ΄t stop chewing :)