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

Comparing Characters challenge error, any thoughts/advice?

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' Bummer! I entered Anderson and expected to get back line 1 as A comes before M.


Not sure why my code isn't solving the above problem. Any advice?

Sorry this is my first time asking a question and i'm just wondering why I can't see my code when I checkmarked the box that said "attach my code"?

2 Answers

Hi Swagat,

The "attach my code" button is a little bit buggy right now. You can post your code with the correct formatting using this guide. However, passing code would be as follows;

public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {
    int line = 0;
    if(lastName.charAt(0) > 'M') {
      return line = 2;
    } else
    return line = 1;
  }
}

Please let me know if you have any questions about why this works!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Swagat,

look at my suggested code:

public class ConferenceRegistrationAssistant {

  public int getLineFor(String lastName) {
    int line = 0;
    if(lastName.charAt(0) > 'M') {
// the getLineFor method takes a String "lastName" as argument
// Strings are concatenations of characters and they can be count from 0 
// you can use the charAt() method to compare the char at the place 0 inside String "lastName"
// with a single character of your interest
// here we write a condition:  if char at position 0 of the  "lastName" is greater then character 'M'
// the line is 2

      return line = 2;
// return int 2
    } else
// everething is under 'M'
// line  is 1
    return line = 1;
// return int 1
  }
}

I hope I could help a little and donΒ΄t hesitate to ask more questions if you need :)

Grigorij