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

Dominik Huber
Dominik Huber
4,631 Points

Why is my code for the challenge not working? Code in details.

Code is attached.

For example if he puts in Anderson it says that he is not in line 1. But why not?

A is greater or equal 'A' (equal in that case) so true & A is not greater then 'M' so also true. Since I used the && true and true should become "true". So the first statement in the if statement should run which is line equals 1. But why it still says he is not in line 1?

I think I made a mistake. Please help me I'm breaking my little brain about this problem :D

Thx

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

  private int line;

  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 */


    if (lastName.indexOf(0) >= 'A' && lastName.indexOf(0) <= 'M' ) {
    line = 1; } else {
     line = 2; 
    }
    return line;
  }

}

2 Answers

All you need to do is after your "line" declaration do an if statement that tests if the first letter of their last name is less than 'N' set line equal to 1 otherwise set it equal to 2. Then right before the method closing curly brace make sure that you return "line".

Hint: to check the first letter of their name use firstName.charAt(0)

Dominik Huber
Dominik Huber
4,631 Points

Thx a ton man you are amazing. Somehow I made a mistake (or a few mistakes). But my main problem here was that I used .indexOf instead of charAt. Now it is working. Thx a ton!