Results 1 to 5 of 5
- 10-07-2012, 06:41 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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.
- 10-07-2012, 07:20 AM #2
Member
- Join Date
- Mar 2012
- Posts
- 26
- Rep Power
- 0
Re: Why are my if statements not working?
Check out the String class in the api for comparing methods
- 10-07-2012, 07:32 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 49
- Rep Power
- 0
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)
- 10-07-2012, 08:25 AM #4
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
Re: Why are my if statements not working?
Thanks a bunch!
- 10-07-2012, 09:27 AM #5
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.
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
If Statements
By WillHorne in forum New To JavaReplies: 7Last Post: 03-01-2012, 12:47 PM -
\n not working in GUI (working code, but \n isn't working)
By cc11rocks in forum New To JavaReplies: 2Last Post: 01-04-2011, 04:30 AM -
if statements not working
By pizzadude223 in forum New To JavaReplies: 6Last Post: 08-01-2010, 06:05 PM -
The code isnt working unless I add print statements at diffrent points!:confused:
By Addez in forum New To JavaReplies: 6Last Post: 11-12-2009, 10:50 AM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks