View Full Version : Got a question about declaring variables
05-17-2006, 01:13 AM
If this is part of my code:
double costKwhr = Double.parseDouble(costKwhrField.getText());
double consumedKwhr = Double.parseDouble(hoursPerYearField.getText());
would I need to declare: costKwhr and hoursPerYear as doubles?
05-17-2006, 04:03 AM
Well to answer that with a question....If you are parsing a string using the parseDouble method which returns whatever it parses as datatype of double and you want to assign that resulting data that is of datatype double to another variable what datatype should the variable probably need to be to handle data of type double?
You already have costKwhr declared as a double. As for hoursPerYear I assume you meant hoursPerYearField then it is obviously a variable that is going to be holding a string. It looks to be part of the TextComponent class judging from the .getText() method that goes with it. Not sure why you would think that needs to be declared a double. It is actually a reference to the object you created from that TextComponent class and not a variable.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.