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

I entered Zimmerman and expected to be in line 2 since Z i after M

Here is my code:

int line = 0; int line1 = 0; int line2 = 0; char letter = lastName.charAt(0); if(letter>='A'||letter<='M'){ line1++; line=line1; }else{ line2++; line=line2; }

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;
    int line1 = 0;
    int line2 = 0;
    char letter = lastName.charAt(0);
    if(letter>='A'||letter<='M'){
      line1++;
      line=line1;
    }else{
       line2++;
       line=line2;
    }

     return line;
  }
}

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi,

your first conditional statement is true because Z is greater then A and line 1 will be returned. Delete the first condition and your logic will be fine.

Your code is a little bit overcomplicated:

See here a more cleaner suggestion:

  public int getLineFor(String lastName) {

    int line = 0;
// one line variable is enough
    if (lastName.charAt(0) < 'M') {
// inside the parenthesis get the first character
// proof it against 'M'
      line = 1;
    } else {
      line = 2;
    }
    return line;
// return the value in dependance of the first character
  }

Makes sense?

Grigorij

thank you... You ROCK !!!!

Ivan =D

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Thanks Ivan!!!

See you in the forum :))))