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

Joseph Jaber
Joseph Jaber
646 Points

Dereference Error

This question doesn't state that we are assuming the characters are upper-or-lower cases. So to be safe I want to convert the letter to upper case using this code: lastName.charAt(0).toUpperCase()

Problem is this gives me a dereference error message. I don't see why this shouldn't work.

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 */
    if (lastName.charAt(0).toUpperCase() <= 'M'){
      return 1;
    }
    else{
      return 2;
    }
  }

}

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

So when you use chaining, be sure to read it from inside to the outside.

You are starting with a String then calling charAt(0) which is returning the 1st Character of the String. But the return Type is now Char NOT String. Char and String both use a method called toUpperCase but they work slightly different.

If you look at the method toUpperCase under each doc. You will see that slight difference.

Char doc

String doc

Let me know if this hint helps or if you are still stuck.

Joseph Jaber
Joseph Jaber
646 Points

Thanks for the help! But I still can't seem to find a solution to what I'm doing. Is there maybe a similar method to "toUpperCase" that is for chars?