| | |
If
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I strongly suggest that you read through the tutorial.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Let's have a look at what is happening in the two blocks you have posted then.
Block 1: Block 2: In Block 1, you are saying if the temperature is above 90 degrees, subtract 4 (I'll assume days) days from the shelflife.Meanwhile, in Block 2, you are saying if the temperature is above 90 degrees, subtract 4 days from the shelflife and let that value be called shelflife from now on.
IE, the outside temperature is 92 degrees and the current value of shelflife is 30 days. After Block 1, shelflife is still equal to 30 days, because you haven't told the program to actually change the value stored in the variable. After Block 2 however, you have told the program to change the value stored in the variable, and shelflife is now equal to 26 (IE it's previous value minus 4 days).
Block 1:
Java Syntax (Toggle Plain Text)
if(outsdieTemperature > 90){ shelfLife-4; }
Java Syntax (Toggle Plain Text)
if(outsideTemeratures > 90){ shelfLife=shelfLife-4; }
IE, the outside temperature is 92 degrees and the current value of shelflife is 30 days. After Block 1, shelflife is still equal to 30 days, because you haven't told the program to actually change the value stored in the variable. After Block 2 however, you have told the program to change the value stored in the variable, and shelflife is now equal to 26 (IE it's previous value minus 4 days).
Please anyone, correct me if I am wrong. It is the best way for me to learn.
There are now 2 possibilities. I'll get to them after a bit of background.
If the variable shelf life isn't being changed, look at the conditional (the bit after If which tells the program the circumstances in which to run the statements in the {}).
In this case, the conditional is (outsideTemeratures > 90). If this evaluates as True, the variable shelfLife will be changed, if it evaluates as False, the variable shelfLife will not be changed.
Now, the possibilities. The first is that you made a typo when you wrote the If block. You have three different spellings of what seems to be the same variable (outsideTemperature in the declaration; outsideTemeratures in the second try at the If block and outsdieTemperature in the first try). Check that your spelling of each variable is the same throught the program.
If the program still doesn't change the value of shelfLife after you have checked your spelling, then answer me this:
If the variable shelf life isn't being changed, look at the conditional (the bit after If which tells the program the circumstances in which to run the statements in the {}).
In this case, the conditional is (outsideTemeratures > 90). If this evaluates as True, the variable shelfLife will be changed, if it evaluates as False, the variable shelfLife will not be changed.
Now, the possibilities. The first is that you made a typo when you wrote the If block. You have three different spellings of what seems to be the same variable (outsideTemperature in the declaration; outsideTemeratures in the second try at the If block and outsdieTemperature in the first try). Check that your spelling of each variable is the same throught the program.
If the program still doesn't change the value of shelfLife after you have checked your spelling, then answer me this:
Is the temperature outside actually greater than 90 degrees?You have initialized the temperature variable as 80 degrees, and that is lower than 90 degrees. If the value of the outsideTemperature is not changed between the initialisation and the If block then the If block's conditional (see paragraph 3) will evaluate as False (ie the temperature outside is not greater than 90 degrees) and the statements inside the If block will be skipped.
Last edited by DavidRyan; Oct 23rd, 2006 at 9:35 pm.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
![]() |
Other Threads in the Java Forum
- Previous Thread: Rubiks cubes little brother (lol)
- Next Thread: Please Helppp..i Really Need To Pass The Coursework.its Due Soon
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






