Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Compute Wind Chill Assignment

1. ## 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...

```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

2. ## 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:

```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);
}
}```

3. ## The Following User Says Thank You to Brt93yoda For This Useful Post:

JavaPF (September 14th, 2010)

4. ## 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.

5. ## Re: Compute Wind Chill Assignment

Glad to hear you understood the problem. Happy programming!

6. ## 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?

```//Format to keep the windChill to 2 digits after decimal
windChill = (int)(windChill*100)/100.0;```

7. ## Re: Compute Wind Chill Assignment

Try it both ways and see which gives the desired results.

8. ## 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....