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

Sorawit Kongnurat
Sorawit Kongnurat
1,284 Points

Error cannot find symbol for M

Java is the first programming language I am learning. (I actually forgot everything I learnt in Swift, even then I was still in the early stages.) I don't know if this is only me but I have been having more and more problem understanding the course. Could this be because I am learning new things, and is this a good thing to have?

import java.io.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 */
    Console console = System.console();
    String lastNameString = console.readLine("Enter your lastname: ");
    char name = lastNameString.charAt(0);
    return name;
    if (name <= M) {
      int line = 1;
      return line;
    } else {
      int line = 2;
      return line;
    }
  }

}

3 Answers

You have to put M between quotes

if (name <= 'M')
Sorawit Kongnurat
Sorawit Kongnurat
1,284 Points

As Andie said the answer the answe is till wrong. Thank you for the fix on M though. I should have seen it in the question.

As Lee said you have to put the char M in quotes. Also you shouldn't return name because your program is expecting you to return an int. If you return a char it should either give an error or caste the char to int (giving its ascii value). Also recall that Strings have a compare() method in Java by which you can find whether one string comes later alphabetically than another string.

int compareTo(String anotherString) Compares two strings lexicographically. int compareToIgnoreCase(String str) Compares two strings lexicographically, ignoring case differences. http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

The int returned by compareTo and compareToIgnoreCase symbolizes whether the string comes before the other string or after alphabettically.

str1.compareTo(str2) will return an integer > 0 if str1 is "greater than" str2, an integer < 0 if str1 is "less than" str2, and 0 if str1 = st2.

Sorawit Kongnurat
Sorawit Kongnurat
1,284 Points

This might be the way to solve it but I never knew this from the tutorial or was it in the eariler part of the course?

I'm not sure I haven't done that course. I learned Java in school. I just thought that might help since its simpler than taking the first char out of the string.

Sorawit Kongnurat
Sorawit Kongnurat
1,284 Points

Look like I solved it. Yay! However, I have misunderstand the question again... getLineFor is already executed. What I needed to do was if (lastName.chartAt(0) <= 'M')...

I feel like I'm so bad at programming ... Even explaining what I just done is hard.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Sorawit,

look here, I explained the challenge in little bit there.

https://teamtreehouse.com/community/cant-succeed-that-challenge

To be honest, the course is not easy at all. I am also a programming beginner and Java is my first step into this new world :) Take your time. Donยดt try to run through the lessons and solve the challenges to complete the course. I rewatch many videos in the Java track, because I feel that I need more time to grasp the whole logic.

Donยดt give up and you will get better, but it will need time and patience ...

If you need more help or motivation, let me know ...

Grigorij

Sorawit Kongnurat
Sorawit Kongnurat
1,284 Points

Thank you I solved the problem but I had to look around to get an idea. I didn't know that I could just pass string. (I was trying to find the string and more it harder for myself) Yes, I won't give up.

Thank you