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

Sohaib Rashid
Sohaib Rashid
627 Points

I'm not sure what the inital step is, if somebody can help it would be great! Happy Coding!

The lastName should be a char but the task says it isnt and i know a boolean should be in there but I dont know how to add it. The task is as follows: I have modeled an assistant for a tech conference. Since there are so many attendees, registration is broken up into two lines. Lines are determined by last name, and they will end up in line 1 or line 2. Please help me fix the getLineFor method.

NEW INFO: chars can be compared using the > and < symbols. For instance 'B' > 'A' and 'R' < 'Z'

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

}

1 Answer

Hi Sohaib!

The getLineFor method takes in a string that appears to be an entire last name. In order to sort the attendees by last name, you're going to want to get the first character in the lastName and then use that to decide which line they go in.

In the video before this code challenge at around 1:39, Craig explains the method that you need to use: charAt().

For example:

String greeting = "Hello";
char firstLetter = greeting.charAt(0)); // This will equal 'H'

Also, keep in mind that characters need to be in single quotes. So, in your if conditions the M should be 'M'.

Hope that helps!

Edit: Also, just noticed that you added a condition to your else statement. That shouldn't be necessary in this case. However, in the future if you do want to add a condition, you can use else if (condition). Check out this resource if you want more information.

Where do those two lines of code go?

Hey Jonathan! You're not going to be directly using those two lines of code. I was just giving an example of how to use the charAt() method. You're going to want to use that method in order to get the first character of the lastName string that is passed into your getLineFor method, which you can then make comparisons with.

I'm still confused on where the code goes, also, is it necessary to use an if else statement?

Ok, I responded on your other question directly: https://teamtreehouse.com/community/whats-the-proper-answer-to-this-challenge.