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 trial

Java Java Objects (Retired) Creating the MVP Comparing Characters

Mindaugas Rozanskas
PLUS
Mindaugas Rozanskas
Courses Plus Student 978 Points

I am a bit lost in this task

Can anyone give me a hand.

ConferenceRegistrationAssistant.java
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;
    return line;
  }

}

5 Answers

Remember that characters can be compared using the < , > , < = , and > = operators. That is to say, 'B' is greater than ( > ) 'A', 'C' is greater than 'B', and so on.

Compare the first character of the string to the character 'M'. If it's less than or equal to 'M', then you'll set line to 1. Otherwise, set line to 2.

Mindaugas Rozanskas
PLUS
Mindaugas Rozanskas
Courses Plus Student 978 Points

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 */ char letter=lastName.charAt(0); if (letter <='M'){ System.out.println("Line 1"); }else{ System.out.println("Line 2"); }

int line = 0;
return line;

}

} I made it in the first place.But it is still not working.

Mindaugas Rozanskas
PLUS
Mindaugas Rozanskas
Courses Plus Student 978 Points

Or I made 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 */ char letter=lastName.charAt(0); if (letter<='M'){ int line=1; }else{ int line = 2; } int line = 0; return line; }

} Not working

You need to declare int line in the beginning of the function. In that code you're declaring it within the if statements which is limiting the scope of the variable. Declare it above the if statements then change your int line = statements to just line =.

Mindaugas Rozanskas
PLUS
Mindaugas Rozanskas
Courses Plus Student 978 Points

error: variable line is already defined in method getLineFor(String) int line = 0;