Skip to content

Instantly share code, notes, and snippets.

@swaters86
Last active August 29, 2015 14:06
Show Gist options
  • Save swaters86/2bec0892ef8ce1abac6f to your computer and use it in GitHub Desktop.
Save swaters86/2bec0892ef8ce1abac6f to your computer and use it in GitHub Desktop.
package calculatewindchillindex;
import java.util.Scanner;
public class CalculateWindChillIndex {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// GETTING USER INPUT
// Prompt user for ouside temperature and get the value from input and declare it as a double value
System.out.println("Enter the temperature in Fahrenheit between -58°F and 41°F:");
double temperature = input.nextDouble();
// Prompt user for windspeed and get the value from input and declare it as a int value
System.out.println("Enter the wind speed (>=2) in miles per hour:");
int windSpeed = input.nextInt();
// CALCULATING WIND CHILL INDEX
// Declaring converted windspeed constant since the calculation is always the same, set as double
final double CONVERTED_WINDSPEED = Math.pow(windSpeed,0.16);
/*
Actual calculation for getting Wind Speed Index by using:
wind_chill_index = 35.74 + (0.6215 * temperature) - (35.75 * velocity^0.16) + (0.4275 * temperature * velocity^0.16)
*/
double windChillIndex = 35.74 + (.6215 * temperature) - (35.75 * CONVERTED_WINDSPEED) + (0.4275 * temperature * CONVERTED_WINDSPEED);
// PRINTING OUT CALCULATION RESULT
// Display result message
System.out.print("The wind chill index is " + (float) windChillIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment