public class HICalc { //Define variable used to store actual temperature in degrees F. private int temperature; //Define variable used to store percentage relative humidity. private int humidity; //Define variable used to store computed heat index value. private long heatindex = 0; //Define constants used in heat index formula. //We don't have to define these, but makes it easier //to check or change formula. private static final double A1 = -42.379; private static final double A2 = 2.04901523; private static final double A3 = 10.14333127; private static final double A4 = 0.22475541; private static final double A5 = 0.00683783; private static final double A6 = 0.05481717; private static final double A7 = 0.00122874; private static final double A8 = 0.00085282; private static final double A9 = 0.00000199; /******** Constructor Methods ********/ //Construct a heat index calculator object public HICalc() { //Set temperature to default temperature = 80; //Set humidity to default humidity = 0; } /******** Accessor Methods ********/ //Accessor method to retrieve temperature public int getTemp(){ return temperature; } //Accessor method to retrieve humidity public double getHumid() { return humidity; } /******** Mutator Methods ********/ //Mutator method to set temperature public void setTemp(int inTemp) { if ((inTemp < 80) || (inTemp > 110)) throw new IllegalArgumentException("The temperature you entered, " + inTemp + ", is out of range for this heat index calculator. " ); temperature = inTemp; } //Mutator method to set humidity public void setHumid(int inHum) { if((inHum < 0)||(inHum > 100)) throw new IllegalArgumentException ("Humidity must be an integer" + "between 0" + " and 100, inclusive, representing " + "percentage relative " + " humidity."); humidity = inHum; } //Mutator method to compute heat index based on temperature and humidity public void computeHi() { double tempheatindex = ( A1 + ( A2 * temperature ) + (A3 * humidity) - (A4 * temperature * humidity ) - (A5 * Math.pow (temperature, 2)) - (A6 * Math.pow (humidity, 2)) + (A7 * Math.pow (temperature, 2) * humidity) + (A8 * temperature * Math.pow (humidity, 2)) - (A9 * Math.pow (temperature *humidity, 2))); heatindex = (Math.round ((100 * tempheatindex)/100)); } /******* Facilitator ("Helper" Methods) ********/ //Facilitator method to provide warning associated with heat index categories. public String showWarning() { if (heatindex >= 130) return "This heat index value is in the category of Extreme Danger, " + "with heat stroke or sunstroke likely for people in high risk groups."; else if ((heatindex >= 105) &&( heatindex <= 129)) return "This heat index value is in the category of Danger, with sunstroke, " + "muscle cramps, and/or heat exhuastion likely. Heatstroke possible" + "with prolonged exposure and/or physical activity by people in high" + "risk groups."; else if ((heatindex >= 90) && (heatindex <= 104)) return "This heat index value is in the category of Extreme Caution, with" + "sunstroke, muscle cramps, and/or heat exhuastion possible" + "with prolonged exposure and/or physical activity by people in high" + "risk groups."; else if ((heatindex >= 80) && (heatindex <= 89)) return "This heat index value is in the category of Caution, with fatigue" + "possible with prolonged exposure and/or physicl activity by people "+ "in high risk groups."; else return "No heat-related warning are associated with" + " this heat index level"; } /******** toString Methods ********/ //Returns a useful String representation of the heat index object public String toString() { return "The heat index for a temperature of " + temperature + " degrees F" + " and relative humidity of " + humidity + "% is: " + heatindex + " degrees F"; } }