/**
* Same as Weather.java, except we've ADDED:
*   (1) class variables
*   (2) a simple "if" statement
*   (3) demo of scope
*
* @author (Michael Branicky)
* 09/12/2006
*/

import java.util.Scanner;

public class Weather2
{
  /**************** BEGIN NEW ***********************/

  // declare two constant class variables (just like Math.PI, Math.E)

  public static final double absoluteZeroC = -273.15, absoluteZeroF = -459.67; 
  //            ^^^^^
  //            reserved word indicating these are
  //            constant values that can't be changed

  /**************** END NEW *************************/

  // Convert from degrees Fahrenheit to degrees Celsius
  public static double convertF2C (double tempF) {
    return (tempF-32.0)*5.0/9.0;
  }

  // Compute the WindChill index (degrees F)
  public static double windChillIndex (double v, double t) {
    double v_part;  // local variable
    
    /**************** BEGIN NEW ***********************/

    if (v < 4.0) {
      System.out.println("ERROR (windChillIndex): windspeed must be >= 4 mph");
      return -10000.0;
    }
    if (t > 50.0) {
      System.out.println("ERROR (windChillIndex): temperature must be <= 50 F");
      return -10000.0;
    }

    /**************** END NEW *************************/

    v_part = 0.474677 - 0.020425 * v + 0.303107 * Math.sqrt(v);
    return 91.4 - v_part * (91.4 - t);
  }

  public static void main(String args[])
  {
    // Create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );

    // Variables to be used
    double windSpeed, tempFahr, vPart, windChill;

    // Get user input
    System.out.print("Enter temp. (F) and wind speed (mph): ");
    tempFahr = input.nextDouble();
    windSpeed = input.nextDouble();

    // Display output
    System.out.printf("Temp. in Celsius is %f\n", convertF2C(tempFahr));
    
    windChill = windChillIndex(windSpeed, tempFahr);
    System.out.printf("Wind Chill index is %f F = %f C\n", windChill, convertF2C(windChill));

    /**************** BEGIN NEW ***********************/

    // Just to demo class variables ...
    System.out.printf("\nAbsolute Zero is %f F = %f C\n", absoluteZeroF, absoluteZeroC);

    // Just to demo scope of local variables ...
    // The following line gives a BUG because v_part is only available inside windChillIndex
    // System.out.printf("\n v_part is %f \n", v_part);

    /**************** END NEW *************************/
  }
}
