Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import javax.swing.JOptionPane;
- public class question2{
- public static void main(String[] args) {
- while(Repeat!=0);
- String tempString = JOptionPane.showInputDialog(null, "Enter the temperature in Fahrenheit degrees", "Input", JOptionPane.QUESTION_MESSAGE);
- int temp = Integer.parseInt(tempString);
- //Confirms the temperature is within range
- if ((temp>41)||(temp<-58)) {
- JOptionPane.showMessageDialog(null,"The temperature must be between -58 and 41F°");
- int Repeat=1;
- }
- String mphString = JOptionPane.showInputDialog(null, "Enter the wind speed in mph", "Input", JOptionPane.QUESTION_MESSAGE);
- int mph = Integer.parseInt(mphString);
- if (mph<2){
- JOptionPane.showMessageDialog(null,"The wind speed must be higher than 2 mph.");
- }
- //The actual equation.
- double twc=35.74+0.6215*temp-35.75*Math.pow(mph,0.16)+0.4275*Math.pow(mph,0.16)*temp;
- DecimalFormat f2 = new DecimalFormat("##.#F°");
- //This will display wind chill in a message dialog box.
- JOptionPane.showMessageDialog(null,"The wind chill is " +f2.format(twc),"Message", JOptionPane.INFORMATION_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement