Newbie with Java Programming (If statements and Doubles)? - java furniture
I am a beginner in Java programming and am having problems with a part of my program. Heres a piece of code to the end.
Option4 JOptionPane.showInputDialog = (String For Furniture Design Upholstery type-1 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n "+
"Give it to all the above plus captains chairs with leather upholstery 2 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n" +
"Above all, more plush carpet and tile panels Cermaic Enter 3 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n" +
"Above all, the kitchen and bathroom with gold and Agenda sauna and Jacuzzi type 4 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n");
if (Integer.parseInt (Option4) == 1)
(
Double opt4 = 15000;
)
else if (Integer.parseInt (Option4) == 2)
(
Double opt4 = 20000;
)
else if (Integer.parseInt (Option4) == 3)
(
Double opt4 = 30000;
)
else if (Integer.parseInt (Option4) == 4)
(
Double opt4 = 35000;
)
other
(
String ErrorMessage = "Invalid entry for mobile home."
E.printStackTrace (null, error ...
)
/ ** This is the part of the calculations
*
* /
= Opt1 totalHomeCost opt3 double OPT2 + + + opt4;
for some reason, always to the error that it is not they find symbol / variable Opt1 etc. OPT2 all my variables in the same conditions as stated above with the case statements, why did you leave me custom set?
Friday, January 15, 2010
Java Furniture Newbie With Java Programming (If Statements And Doubles)?
Subscribe to:
Post Comments (Atom)
2 comments:
Opt1 is defined, OPT2, etc. within the FI. This means that once the program goes outside the if go () statements reflect the variable "self" and no longer valid. They shuold be defined before when they assign () and values to them only in the IF ()-bit. In this way, remain with the new values, if required in the calculation.
Example:
====================================
Double opt1 = 0, OPT2 = 0, opt3 = 0;
...
If (.) (Opt1 = 1;)
Other (OPT2 = 2;)
double result = opt1 + OPT2;
====================================
Edit: So effectively Integer.parse (Option4 bit) only once, when assigning value to a variable, but analyze and over again in each case () to verify the statement. In parallel, you must use a switch () statement. It is more efficient and more clear that long if ():
====================================
int result =) Integer.parse (Option4;
Double opt4 = 0;
string errorMessage = "";
switch (more) (
Case 1: break opt4 = 15000;
Case 2: break opt4 = 20000;
Case 3: opt4 = 30000 break;
Case 4: opt4 = 35000; break;
Default: errorMessage = "...."; break;
)
totalHomeCost double OPT2 = opt1 + + opt3 + opt4;
====================================
I think your problem with the place of registration.
because if the program does not issue any statement, if for some reason
The program leading directly to the other, then the calculation of the time it is sub, because no dose is declared in the ELSE
try to declare variables of the IF) statement (a good idea. Or) in each IF and ELSE (a bad idea.
Post a Comment