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

Willem Menu
Willem Menu
5,200 Points

Can someone pls tell me what I am doing wrong?

This should be a method that gets the line value based on the last name of a person. A to M should be in the line variable with value 1 and M to Z should be in the line variable with value 2. I've tried this method in java-repl, but the only value for the line variable get is 1.

I would really appreciate it if someone could tell me what I am doing wrong and could explain what I should change to make it work properly.

I am Dutch so excuse my English

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 = 1;
    char firstLetter = lastName.charAt(0);
    if(firstLetter > 'm'){
    line=2;
    } 
    return line;
  }

}

2 Answers

Marcus Eley
Marcus Eley
16,213 Points

Hello William,

It looks like the thing that is throwing you off is case sensitivity. If you compare against 'M' as opposed to 'm' the program as you have posted it here will return the correct values.

if(firstLetter > 'M')

The challenge then will request that you solve it with an else clause. I believe that you will be able to solve it from there.

I hope that helps

Marcus

Willem Menu
Willem Menu
5,200 Points

Thanks man :D, I solved it. Didn't knew it was case sensitive.... I also added an else clause, but I would also worked without one right?

-Willem

Marcus Eley
Marcus Eley
16,213 Points

Yes, the code absolutely would have worked without an else clause. The challenge itself just required one.

I am glad that I could be of help

-Marcus