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

Bummer! I entered Zimmerman and expected to get back line 2 as Z comes after M

public class ConferenceRegistrationAssistant {
  String lastName = "Zimmerman";
  public int getLineFor(String lastName) {
    //mlastname = lastName;
    /* If the last name is between A thru M send them to line 1
       Otherwise send them to line 2 */
    String ABCs = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int line = 0;
    int line2 = 0;
    if (ABCs.indexOf(lastName) <= 12){
        line += 1;
    }else{
        line2 += 1;
    }

    return line;
  }

}

well I think the goal here is to make it so that line is incremented whenever someone has a name that starts with a value less than 1

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 */
    String ABCs = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int line = 0;
    int line2 = 0;
    if (ABCs.indexOf(lastName) <= 12){
        line += 1;
    }else{
        line2 += 1;
    }

    return line;
  }

}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I think you're doing pretty well here, but I think the main problem is you're misunderstanding what they want. They have a conference going on and to get in there are going to be two lines, because there just isn't room enough for everyone to be in the same line or (more likely) it goes faster if we have two. So if your last name is Anderson you should be assigned to line 1. But if your last name is Martin or Zimmerman you should be in line 2. So all we really need to look at is the first letter of the name being sent in. Take a look at my solution:

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

}

We initialize line to 0 because we don't yet know which line the person will be in. Then we look at the character in position 0 of the string (the first letter). If that letter is less than M we assign them to line one. Otherwise they're assigned to line two. Hope that makes sense!

kevin nisay
kevin nisay
1,159 Points

im also looking for an answer on that question . and thanks Jennifer Nordell. look at my code im suffering here for about 1 anda half day figuring out the answer .

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 line =0;
    if ('A' <= 'M') {
      line++;
     return line;
    } else {
      line2++;
     return line2;
    }
  }

}

that was my code before , can you explain me further if you have some time , thank a lot.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, kevin nisay! Well to begin with you declare a single variable twice called line. And then later, you try to use an undefined variable line2. You never declared this.

It seems like to me you might have misunderstood the problem. Your code indicates that you were trying to increment the amount of people in a line given their name. That's not really what we're trying to do.

Here's the scenario. A person walks up to check into a conference. The person there to greet them has to tell them which line to go to. That line has their badges for their entrance. If the person goes to the incorrect line, they'll have to be sent to the correct one to retrieve their badge. So the initial person to greet them needs to tell them line number one or line number 2. We only need one variable to do this... line. The value for line can be set to either one or 2.

If their last name begins with a B they'll go into line 1. If their last name begins with an S, they'll go to line 2.

Hope that helps clarify things! :sparkles:

kevin nisay
kevin nisay
1,159 Points

hi Jennifer Nordell , thank you so much i understand it very well, the way you explained it to me . anyways i would like to ask ive been here for a week , and still i cannot understand all, on my own the java and i know i cant code on my own , is it normal or what can i do to make my self better. ?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

kevin nisay it's not at all uncommon! I dare say that when you were learning algebra, you didn't learn it all in a week. And this sort of thinking is very similar. Learning to solve a problem takes time, skill, and above all, practice!

As an example, when you were learning algebra, you didn't just solve one problem and then move onto the next section. You did multiple problems of the same type over and over until you really understood how that problem was solved. Then, and only then, did you move on to the next type of problem.

So hang in there and keep practicing! :sparkles: