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

I 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 :-).

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 line1 = 0;
    int line2 = 0;
    if(lastName.charAt(0) <= 'M'){
        line1 += lastName.charAt(0);  
        return line1; 
    }
    else{
        line2 += lastName.charAt(0);
        return line2;
    }

  }

}

So you're returning an int but in your code you're trying to add a string(char) to line1 or line2?

line1 += lastName.charAt(0);
line2 += lastName.charAt(0);

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

line1++
line2++ 

might work?

2 Answers

It 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
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

In this assignment they are not requiring to call function.