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

Ben Mair
Ben Mair
8,728 Points

Conference Registration

I am confused again.......I'm not getting any syntax errors and yet it won't let me pass go........

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

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

}

1 Answer

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

Hey Ben, you're very close on this.

Just a few slight changes.

First, your if statement is checking to see if the fieldName.charAt(0) is greater than 'M' which is fine, but if that condition is true we move them to line 2, not line 1.

Secondly and the only other thing that needs to change is that you are having the line printed out in a statement,

really all that needs to be done is you change the variable, such as line = 2;

This is just me being nitpicky, but I'm move your return statement down a line as well.

Overall, very good job. I used your code and I changed the System.out.println fuctions and just changed them to return lines and this code passed fine.

Here's your code with the minor edits.

public class ConferenceRegistrationAssistant {

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

}

Thanks, let me know if this helps or not. Also if you want to have line =1; at the we just need to change it to

public class ConferenceRegistrationAssistant {

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

}

Though your way works just fine too.

Thanks, good job Ben!