Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Comparing Characters

I have modeled an assistant for a tech conference. Since there are so many attendees, registration is broken up into two

why it is not working

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('A'<=lastName.charAt(0)<='M')
    {
     line=1; 
    }
    else
    {
      line=2;
    }
    return line;
  }

}

2 Answers

The problem is this line:

if('A'<=lastName.charAt(0)<='M')

Try this instead:

if(lastName.charAt(0) <= 'M')

What it is saying is that if the first char in the lastName is less than or equal 'M' then ... You can use the comparison operators with chars because behind the scenes chars are really ints. 'M' is an int with the ASCII value of 76. 'A' has an ASCII value of 64, so it is less than 'M', etc.

Tristan Smith
Tristan Smith
3,171 Points

Good morning Anish,

You're on the right track!

Edit: I just realized what no coffee in the morning does to me! Please read again.

The challenge wants you to check whether or not the last name's first character is between 'a' and 'm'. Keep on eye on those '>' and '<' symbols.

As a side note: When you use an if statement with multiple conditions you separate them with logical operators such as 'and' or 'or'. Shown in code as, without the quotes, "&&" and "||"

This video gives a good example of using the two: https://teamtreehouse.com/library/java-basics/perfecting-the-prototype/censoring-words-using-logical-ors

/* When you use &&, both conditions must be true in order for it to use what's inside the if statement
        Otherwise it will continue onto the else if one is there*/

    if("Johnny" != "James" && "James" != "Sarah"){
       // Names are different
    }

// If using || (or), only one of the conditions must be true for it to use what's inside the if statement

    if("Johnny" != "James" || "James" != "James"){
       // Names are different
    }