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

java objects challenge

I am kind of confused by this challenge. In the lesson they imported the console class; was I not supposed to do this? Also I am getting an error message when using < and >. The instructions say that I am meant to use these, so why am I getting an error message? What do I need to to to fix this code?

ConferenceRegistrationAssistant.java
import java.Console;
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 firstLetter.console.readLine("Enter first letter of your last name:  ");
     Console console = System.console();
    char entry= firstLetter.charAt(0);
    if(firstLetter < 'M'){
      System.out.println("Please go to line 1.");
    } else {
      System.out.println("Please go to line 2.");
    }


  }

}

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Matt,

  • We actually don't need to import the console class (we would've imported Java.io.Console if we did), because we don't need to get any input from the user in this challenge. In this challenge, we are going to run the if test against the first letter of the argument that's passed in (in this case, we're recognizing it as lastName).

  • Since we don't need to get input from the user we don't need that readLine statement, but if we did, you'd want to begin it with 'String firstLetter = console.readLine', rather than 'String firstLetter.console.readLine'. We would be assigning the value of the readLine method call to firstLetter.

  • Instead of telling the user if they belong in line 1 or line 2, we'll change the value of the line variable to indicate that, and then return that value from this method. By doing it this way, we've programmatically stored a value indicating to us if the person belongs in line 1 or line 2.

Here's an example of how you might solve this one:

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;   
    char firstLetter = lastName.charAt(0);

    if(firstLetter < 'M'){
      line = 1;
    } else {
      line = 2;
    }
    return line;

  }
}