Windchill
Back to the Program-A-Day homepage
ProblemAs 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.
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 | |
---|---|---|
SolutionStart off by declaring your variables. You will need variables for all the different data included. Temperature, windspeed, and windchill will all be input by the user. Location will also be input by the user. You must declare a String "temp" to be used for initializing variables. double temperature; //temperature amount double windspeed; //wind speed amount double windchill; //windchill amount String location; //the location String temp; //temporary string for initializing //variables Your next step will be to get the proper input from the user. You will use JOptionPane to get the information, and then parseDouble to glean the actual data from the input. Remember that JOptionPane will return a String, so parseDouble must be used to convert this to usable data. 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 The next step is fairly straightforward. This is the part of the program that will do the actual calculations. Math.pow can be used to utilize exponents in a formula. The first parameter is the variable, and the second parameter is the exponent. windchill = 13.12 + .6215*temperature - 11.37 * Math.pow(windspeed, .16) + .3965 * temperature * Math.pow(windspeed,.16); Finally, you must print out the output so the user can obtain the information. This is fairly simple, you can just use System.out.println to show all the relevant data. It is also good practice to output a message that indicates to the user that the program has finished all processing. Congratulations, you should now have a working program that determines the temperature with windchill. Never again will you be forced to blindly trust the weather network. 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**"); | ||
Code |