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 Prompting for Guesses

Jeff Janes
Jeff Janes
8,033 Points

Totally lost on Conference Registration Assistant challenge

Not even sure how to start this challenge...how would I compare within a range of characters?

Anyone have the completed code I can look over?

3 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there Jeff, let's see if I can help with this.

Basically the first thing you do is make an if statement to compare your char, your assumption is correct it is a lastName.charAt(); code that we use.

First off, set your line variable at the top, so the if/else statement can correctly modify it.

The if statement that you want is to check and see if lastName.charAt(0); is less than or equal to M

we'd do this by

if ( lastName.charAt(0) <= 'M')

If this is true we change the line variable to one, otherwise, the only conclusion is that it is greater than M, so our else would be

else {
line = 2;
}

After combining this all together it would look something like.

public class ConferenceRegistrationAssistant {

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

}

Thanks, let me know if this helps or not.

Jeff Janes
Jeff Janes
8,033 Points

Here I was overcomplicating things thinking I had to set two separate values for A-M and N-Z. Thank you SO much Rob for the quick response, means more than you know! :)

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Glad I could help, and I definately understand the over complicating it part. I look back at some of my older programs that I first did and I think "Why the heck did I even try to do it this way.."

It definitely gets easier and you can laugh at yourself afterwords, we all do.

Safira Nugroho
Safira Nugroho
3,910 Points

Hi, I just want to quickly ask one thing - why do we need to write the '''java int line = 0; ''' command? I'd appreciate it if you can quickly elaborate on that. :-)

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

We need to set an int variable since the method returns an int. We also need to declare it above the loops so that they can access them.

Basically we do it so that the method has something to modify and return with the correct value.

Yongshuo Wang
Yongshuo Wang
5,500 Points

Hi, If you need to compare two range of characters (String), you need to use function equals.

String firstString = "First Name";

firstString.equals("First Name");
Jeff Janes
Jeff Janes
8,033 Points

I wouldn't use the .charAt() method?