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

Jordan Ernst
Jordan Ernst
5,121 Points

what is this question asking me to do?

i don't know what it is wanting me to do here and what methods i use. can someone steer me on the right path please?

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;
    if (lastName.charAt(0) <= lastName.charAt(12)){
      line= 1;
    }
    else {
      line= 2;
    }


    return line;
  }

}

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

Okay, so what he wants is for you to check the first character of the last name and figure out if they go to Line 1 (starts with A through M) or line 2 (letters N-Z)

The second part of the task might help a bit:

chars can be compared using the > and < symbols. For instance 'B' > 'A' and 'R' < 'Z'

So you've got the idea, where you do lastName.charAt(0) because you're snagging the first character of the last name. Now you just have to think about what you want to compare that character to.

Remember that B is greater than A, so A is less than B (obv right?)

So how I thought about it was "If the cutoff is M, should I just check the character to see if it's less than N?"

Then just set up the if statement to check if their last name starts with a character less than N, set line to 1, else set it to 2.

This works because chars are comparable, so they can use comparison operators like < > == just fine. It's just remembering that A is "smallest" and Z is "greatest" and you're all set.

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;
  }
}
Jordan Ernst
Jordan Ernst
5,121 Points

thanks a lot yeah i tried the code like this but realize after this that missed the single quotes. thanks man!