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

Charlie Gallentine
Charlie Gallentine
934 Points

I'm not sure where to start. Could someone please walk me through this challenge?

I've been working on this for a while, but I am utterly lost. Any help would be greatly appreciated! Thank you!

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;
    return line;
  }

}

Hi Charlie, Could you please provide a link to the direct challenge? I think we could better help you then.

2 Answers

anil rahman
anil rahman
7,786 Points

Could also do this extra check so charlie might understand it better seen as though question says between A and M

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 between A and M (the charAt(0) means grab the first letter of my last name)
    if(lastName.charAt(0) >= 'A' && lastName.charAt(0) <= 'M'){
      line = 1;
    }
    else{
      line = 2; 
    }
    return line;
  }

}
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Charlie,

  public int getLineFor(String lastName) {
// the line variable is needed to store the line value and return it later on    
int line = 0;

    if (lastName.charAt(0) < 'M') {
// inside the parenthesis get the first character from the argument using the charAt method
// proof it against 'M', so every first char that is less then M will go into line 1

      line = 1;
    } else {
// if the first character of the name is greater then M -> line 2 will be returned
      line = 2;
    }
    return line;
// return the value in dependance of the first character
  }

Makes sense?

Grigorij

I thought we might kind of want to help him with a walk-through step-by-step, instead of just posting the code, but as long as he get's it, this works as well! :-D

Charlie Gallentine
Charlie Gallentine
934 Points

Thank you! That actually makes far more sense than what I was thinking!

Charlie Gallentine
Charlie Gallentine
934 Points

Thanks! That makes more sense! The comments really help!