Compute Wind Chill Assignment
Not in a rush but trying to adjust my own code for an online class. I wrote this code following an example for computing interest but doesnt seem to like my double assignment. The problem is compute windchill using the formula below. It will only work if temp is between -58 and 41 degrees with the wind is above 2 mph.
windchill =35.74 + (0.6215*outsideTemp) - (35.75*windspeed^0.16) + (0.4275*outsideTemp*windSpeed^0.16)
original code that i made and ran through online compiler to find errors...
Code Java:
import javax.swing.JOptionPane;
public class ComputeWindChill {
public static void main(String[] args){
//Enter outside temperature
String outsideTemp = JOptionPane.showInputDialog(
"Enter Outside Temperature in Farhrenheit. Must be above or equal to -58 degrees and below or equal to 41 degrees.");
//Convert outsideTemp String to a double
double outsideTemp =
Double.parseDouble(outsideTemp);
//Enter outside wind speed
String windSpeed = JOptionPane.showInputDialog(
"Enter Outside Wind Speed in Miles per Hour. Wind speed must be above or equal to 2 MPH.");
//Convert windSpeed String to a double
double windSpeed =
Double.parseDouble(windSpeed);
//Calculate windChill
double windChill = 35.74 + (0.6215 * outsideTemp) - (35.75 * (Math.pow(windSpeed,0.16))) + (0.4275 * (outsideTemp(Math.pow(windSpeed,0.16))));
//Format to keep the windChill to 2 digits after decimal
windChill = (int)(windChill*100)/100.0;
//Display results
String output = "The current outside wind-chill temperature is" + windChill;
JOptionPane.showMessageDialog(null, output);
}
}
I followed another example in the book and it did not work. I would like to know why it doesnt work since i am currently only in chapter 3. Thank you for the 5 minutes of your time. -JavaCow
Re: Compute Wind Chill Assignment
Next time please surround your code in [highlight=java][/highlight] tags. Your problem is that you use different data types, and you use the same name. (outsideTemp was an int and a String) Here is the fixed code:
Code java:
import javax.swing.JOptionPane;
public class computeWindChill {
public static void main(String[] args){
//Enter outside temperature
String outsideTemp = JOptionPane.showInputDialog(
"Enter Outside Temperature in Farhrenheit. Must be above or equal to -58 degrees and below or equal to 41 degrees.");
//Convert outsideTemp String to a double
double outsideTempDBL =
Double.parseDouble(outsideTemp);
//Enter outside wind speed
String windSpeed = JOptionPane.showInputDialog(
"Enter Outside Wind Speed in Miles per Hour. Wind speed must be above or equal to 2 MPH.");
//Convert windSpeed String to a double
double windSpeedDBL =
Double.parseDouble(windSpeed);
//Calculate windChill
double windChill = 35.74 + (0.6215 * outsideTempDBL) - (35.75 * (Math.pow(windSpeedDBL,0.16))) + (0.4275 * (outsideTempDBL*(Math.pow(windSpeedDBL,0.16))));
//Format to keep the windChill to 2 digits after decimal
windChill = (int)(windChill*100)/100.0;
//Display results
String output = "The current outside wind-chill temperature is: " + windChill;
JOptionPane.showMessageDialog(null, output);
}
}
Re: Compute Wind Chill Assignment
I see the difference. What i need to do if i want to change or nest the parameters of the number is to change the name of the variable. Because it started as an int named outsideTemp it needs to be assigned another name to be identified as the double version. Thanks i will highlight next time.
Re: Compute Wind Chill Assignment
Glad to hear you understood the problem. Happy programming!
Re: Compute Wind Chill Assignment
My professor stated in lecture that someone who was studying windchill would want as precise of a number as possible. I would assume that I can eliminate the following statement in my java code because all it does is round. Seeing that this actually takes place after the computation; there should be no issue with removing the statement. Is this a correct assumption?
Code java:
//Format to keep the windChill to 2 digits after decimal
windChill = (int)(windChill*100)/100.0;
Re: Compute Wind Chill Assignment
Try it both ways and see which gives the desired results.
Re: Compute Wind Chill Assignment
Yes I have tried both. It seemed to work just the same so I assumed there is no additional code needed when I removed the statement. Thanks all....