Results 1 to 5 of 5
  1. #1
    icykum is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Unhappy Why are my if statements not working?

    When I print out getEntreePrice (), it is 0.0 everytime.
    class Food{

    //Data Members
    private static final double TOFU_BURGER= 3.49;
    private static final double CAJUN_CHICKEN= 4.59;
    private static final double BUFFALO_WINGS= 3.99;
    private static final double RAINBOW_FILLET= 2.99;
    private static final double RICE_CRACKER= 0.79;
    private static final double NO_SALT_FRIES= 0.69;
    private static final double ZUCCHINI= 1.09;
    private static final double BROWN_RICE= 0.59;
    private static final double CAFE_MOCHA= 1.99;
    private static final double CAFE_LATTE= 1.99;
    private static final double EXPRESSO= 2.49;
    private static final double OOLONG_TEA= 0.99;
    private String Food, SideDish, Drink;

    //Entree
    public String getEntree (){
    Food=JOptionPane.showInputDialog ("What would you like for your entree?");
    return Food;
    }

    //Entree Price
    public double getEntreePrice(String Food) {
    if (Food == "Tofu Burger"){
    return TOFU_BURGER;
    }
    if (Food == "Cajun Chicken"){
    return CAJUN_CHICKEN;
    }
    if (Food == "Buffalo Wings"){
    return BUFFALO_WINGS;
    }
    if (Food == "Rainbow Fillet"){
    return RAINBOW_FILLET;
    }
    else return 0.00;

    }
    Last edited by icykum; 10-07-2012 at 07:00 AM.

  2. #2
    romero4742 is offline Member
    Join Date
    Mar 2012
    Posts
    27
    Rep Power
    0

    Default Re: Why are my if statements not working?

    Check out the String class in the api for comparing methods

  3. #3
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default Re: Why are my if statements not working?

    tip: you compare strings with string.equals(stringtocompare)

    IE:

    Java Code:
    String test = "hello";
    String compare = "hello";
    
    // this will return true.
    test.equals(compare)

  4. #4
    icykum is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Why are my if statements not working?

    Thanks a bunch!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default Re: Why are my if statements not working?

    BB Code List - Java Programming Forum

    db

    edit I gave you the same link in your last thread, which you didn't bother to get back to: What is wrong with my program?

    If you continue to ignore moderator advice, your threads may be closed or removed and you may be banned for a period.
    Last edited by DarrylBurke; 10-07-2012 at 09:35 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. If Statements
    By WillHorne in forum New To Java
    Replies: 7
    Last Post: 03-01-2012, 12:47 PM
  2. Replies: 2
    Last Post: 01-04-2011, 04:30 AM
  3. if statements not working
    By pizzadude223 in forum New To Java
    Replies: 6
    Last Post: 08-01-2010, 06:05 PM
  4. Replies: 6
    Last Post: 11-12-2009, 10:50 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

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