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