Results 1 to 9 of 9

Thread: Simple fix?

  1. #1
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default Simple fix?

    I'm obviously doing something wrong, seeing as I'm getting errors. But, what exactly am I doing wrong? Am I using the OR operator incorrectly?

    This is for a conversational program I'm testing my skills in.

    System.out.println("Hey! nice of you to join me! How are you?");
    if (response.equals ("bad" || "Bad")){
    System.out.println("I'm sorry to hear that. Why so?");}

    That's the only place I'm getting an error. any idea why?
    Help gladly appreciated. Sorry to bother.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    that is not correct syntax for Java. You need to write two separate conditions, one for each version of "bad".

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Or you can use the equalsIgnoreCase method.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You need to make all expressions valid boolean expressions.

    Java Code:
    if (response.equals("foo") ||response.equals("bar")) {
    
    }

  5. #5
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    What kind of error are you getting? Off the bat, I see that you have nothing actually going into your "response" variable.

    you can also do
    Java Code:
    response.equalsIgnoreCase("bad")
    That way the user can type "bad", "bAD", Bad", etc. and it will still return true.

  6. #6
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    I was just about to post an error message, but all is now well. Thanks for the help, and once again, sorry to bug you guys.

  7. #7
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Oh hey, is there anyway for me to make it so if the user inputs something like:
    not tooo badd
    the program just takes keywords, like not too bad, and goes based off of that? Everyone types different and I won't feel accomplished if I couldn't implement this for everyone.

  8. #8
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    Without manually correcting the strings based on what you think they meant, you cannot really do that. Everyone types different, but different is wrong.

  9. #9
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Okay, so if someone said "nothing important", and the only option was "nothing", there would be no way to display the "nothing" message?

Similar Threads

  1. simple app-help please
    By skuzzie in forum New To Java
    Replies: 7
    Last Post: 11-08-2010, 12:07 AM
  2. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 02:55 AM
  3. Simple Help....
    By jpnym15 in forum New To Java
    Replies: 1
    Last Post: 11-11-2008, 02:33 PM
  4. Replies: 2
    Last Post: 05-04-2008, 05:27 PM
  5. simple GUI
    By dim_ath in forum New To Java
    Replies: 3
    Last Post: 01-07-2008, 03:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •