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

Fatimah Ghazal
Fatimah Ghazal
1,848 Points

I get this syntax error: bad operand types for binary operator '>'

bad operand types for binary operator '>'

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {

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


  }

    /* If the last name is between A thru M send them to line 1
       Otherwise send them to line 2 */
    int line = 0;



}

1 Answer

Maciej Torbus
Maciej Torbus
8,137 Points

You get the error because you compare String with char. There are different ways to get specific letter from String. You can use methods like chatAt or substring. Then you will be able to compare the letters.

Please also think about the case where the first letter of last name is actually equal to 'A' or 'M'.

You should declare int line = 0; only once, then change its value whether person goes to first or second line.

Hope it helps. Good luck!

Gendarme Docena
Gendarme Docena
1,509 Points

Can you show the code or provide an example for this please? I've been stuck on it for 2 hours and ended up getting the same error.. not sure how to fix this