AP Computer Science --- Haas --- HeatIndex

The apparent temperature or "heat index" combines the effects of heat and humidity. When heat and humidity combine to reduce the amount of evaporation of sweat from the body, outdoor exercise becomes dangerous even for those in good shape. Overheating can cause serious, even life-threatening conditions such as heat stroke.

If you know the relative humidity "rh" and the air temperature in Fahrenheit "T", then you can use the following equation to calculate the heat index.

Make a class called HotDay which has the following methods:

  1. A zero parameter constructor which creates a new HotDay with an initial temperature = 70 and relative humidity = 0.
  2. A two parameter constructor which allows the user to create a new HotDay with an initial temperature and relative humidity.
  3. getTemperature which returns the current temperature.
  4. setTemperature which changes current temperature to a given value.
  5. getRelativeHumidity which returns the current relative humidity.
  6. setRelativeHumidity which changes the current relative humidity to a given value.
  7. heatIndex which returns the current heat index using the calculation above.
  8. heatWarning which returns the current warning based on the heat index: Caution, Extreme Caution, Danger,or Extreme Danger.

Use the class HotDayTester below which creates and tests Hot Days!!



public class HotDayTester
{
	public static void main(String[] args){
	    HotDay hotday1 = new HotDay(70, 50);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(80);
	    hotday1.setRelativeHumidity(50);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(90);
	    hotday1.setRelativeHumidity(50);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(100);
	    hotday1.setRelativeHumidity(50);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(80);
	    hotday1.setRelativeHumidity(80);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(90);
	    hotday1.setRelativeHumidity(80);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	    
	    hotday1.setTemperature(100);
	    hotday1.setRelativeHumidity(80);
	    System.out.println("Temperature :" + hotday1.getTemperature());
	    System.out.println("Humidity :" + hotday1.getRelativeHumidity());
	    System.out.println("Heat Index :" + hotday1.heatIndex());
	    System.out.println("Heat Warning :" + hotday1.heatWarning());
	    System.out.println("");
	        
	   }
}


******************************************
           OUTPUT OF TESTER
******************************************
Temperature :70
Humidity :50
Heat Index :77.0
Heat Warning :weathers fine...

Temperature :80
Humidity :50
Heat Index :81.0
Heat Warning :CAUTION!

Temperature :90
Humidity :50
Heat Index :95.0
Heat Warning :EXTREME CAUTION!

Temperature :100
Humidity :50
Heat Index :118.0
Heat Warning :DANGER!

Temperature :80
Humidity :80
Heat Index :84.0
Heat Warning :CAUTION!

Temperature :90
Humidity :80
Heat Index :113.0
Heat Warning :DANGER!

Temperature :100
Humidity :80
Heat Index :158.0
Heat Warning :EXTREME DANGER!