import java.util.Scanner; // For user input /** * Compute wind chill given temp. in Fahrenheit and wind speed in miles per hour * Ref.: J. Adams et al., C++: An Intro. to Computing * * @author (Michael Branicky) 09/10/2007 */ // Same as WindChill.java BUT adds two "if" statements public class WindChill2 { public static void main(String args[]) { // Declaration of variables to be used double windSpeed, tempFahr, vPart, windChill; // Create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); // Get user input System.out.print("Enter temp. (F): "); tempFahr = input.nextDouble(); System.out.print("Enter wind speed (mph): "); windSpeed = input.nextDouble(); if (windSpeed < 4.0) { System.out.println("ANSWER NOT VALID: windspeed must be >= 4 mph"); } if (tempFahr > 50.0) { System.out.println("ANSWER NOT VALID: temperature must be <= 50 F"); } // compute v_part vPart = 0.474677 - 0.020425 * windSpeed + 0.303107 * Math.sqrt(windSpeed); // compute wind chill windChill = 91.4 - vPart * (91.4 - tempFahr); // Display output System.out.println("Wind Chill index = " + windChill); } }