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 to this thing :(

How can i complete this challenge? the introduction to the challenge is :

"I have modeled an assistant for a tech conference. Since there are so many attendees, registration is broken up into two lines. Lines are determined by last name, and they will end up in line 1 or line 2. Please help me fix the getLineFor method."

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

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;
  }

}

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Henrique,

Letters are in ASCII and are associated with a number. You can look at an ASCII table here:

http://www.asciitable.com

Notice that the letter 'A' is a decimal: 65, and 'M' is a decimal: 77

Therefore, we can compare characters as if they are numbers.

       if ('A' < 'M') {
           //do something
       } else {
           //do something else
       }

Is the same as saying:

      if(65 < 77) {
        //do something
      } else {
        //do something else
      }

Therefore, what you want to do is get the first character of the name being passed in to the method. Then see if it is less than 'M'. If it is, assign 1 to line. If it is not (else), assign 2 to line.

I hope this helps.

Regards,

Chris

If the first character of the lastName is less than or equal to 'M' then line is equal to 1; else line is equal to 2; Hope that helps!