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

Ben Morse
Ben Morse
6,068 Points

Trouble with the CharS challenge.

I'm stuck on a challenge code. I have to use CharS to compare one char to another char. I thought the syntax for it was

if (lastName.charS() >= 'M')

but i'm getting a class error.

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;
    char letter = '';

    if (lastName.charS(letter) >= 'M') {
      line = 1;
    } else {
      line =2;
    }

    return line;
  }

}

1 Answer

What the challenge is asking is to compare the first letter of the last name which would be done by getting the first character of the lastName string. The part in the description saying "chars can be compared using the > and < symbols." is just saying that you can take a char variable and use basic comparisons just like int variables. There is no charS function involved. Its only a typographical issue that makes it even look like it.

Ben Morse
Ben Morse
6,068 Points

Ah i see. I was thrown off again. Happened in one of his earlier challenges

Ben Morse
Ben Morse
6,068 Points

Okay It worked. Thanks a bunch...it was driving me mad.