|
|
Line 1: |
Line 1: |
| {{1010PrAD|ProblemName=Windchill | | {{1010PrAD|ProblemName=Windchill |
| | | |
− | |Problem= As you know from living in Winnipeg, wind can make the air temperature feel much colder. Write a program that will use Scanner to read in an air temperature and a wind speed. Then use the formula below to calculate and output the windchill. | + | |Problem= As you know from living in Winnipeg, wind can make the air temperature feel much colder. Write a program that will uses JOptionPane to read in an air temperature and a wind speed. Then use the formula below to calculate and output the windchill. |
| | | |
| | | |
Revision as of 19:00, 23 September 2010
Back to the Program-A-Day homepage
Problem
As you know from living in Winnipeg, wind can make the air temperature feel much colder. Write a program that will uses JOptionPane to read in an air temperature and a wind speed. Then use the formula below to calculate and output the windchill.
- <math>T_{wc}=13.12 + 0.6215 T_a-11.37 V^{0.16} + 0.3965 T_a V^{0.16}\,\!</math>
- where <math>T_{wc}\,\!</math> is the wind chill index based on the Celsius scale, <math>T_a\,\!</math> is the air temperature in °C, and <math>V\,\!</math> is the air speed in km/h.
- Equation taken from Wikipedia which cites http://www.msc.ec.gc.ca/education/windchill/science_equations_e.cfm
Hint: Use Math.pow to complete the equation.
Sample output with location Winnipeg, air temperature -10 and wind speed 30:
Location: Winnipeg
Current Temperature: -10.0 Celsius
Wind Speed: 30.0 km/h
Temperature with Windchill: -19.52049803338773
Programmed by A. Student
**End of Program**
|
|
Introducing Math methods
|
Solution
|
Code
Solution Code
import javax.swing.*;
/*****************************************************************************************
Title: Windchill
Purpose: To input different temperatures and wind speeds and calculate windchill
@author A. Student
@version 2010-Sept-22
*****************************************************************************************/
public class Windchill2
{ //opens public class
public static void main (String []args)
{ //opens main method
//variables declared here
double temperature; //temperature amount
double windspeed; //wind speed amount
double windchill; //windchill amount
String location; //the location
String temp; //temporary string for initializing
//variables
//get input
location = JOptionPane.showInputDialog ("What is the location?");
temp = JOptionPane.showInputDialog ("What is the current temperature in Celsius?");
temperature = Double.parseDouble (temp);
temp = JOptionPane.showInputDialog ("What is the wind speed in kms per hour?");
windspeed = Double.parseDouble (temp); //converts windspeed to double
//calculate windchill
windchill = 13.12 + .6215*temperature - 11.37 *
Math.pow(windspeed, .16) + .3965 * temperature * Math.pow(windspeed,.16);
//output
System.out.println ("Location: " + (location));
System.out.println ("Current Temperature: " + (temperature) + (" Celsius"));
System.out.println ("Wind Speed: " + (windspeed) + (" km/h"));
System.out.println ("Temperature with Windchill: " + windchill);
System.out.println("Programmed by A. Student");
System.out.println("**End of Program**");
}//close main
}//close public class
|
Back to the Program-A-Day homepage