/*
  This version of the TemperatureReading class throws
  an IlleagalArgumentException in the setTemperature()
  methods if the input data is not valid. This is
  better than just setting the input data to some
  default value. Notice that the constructor will
  also throw this exception if given invalid input
  since the constructor calls the set methods.
*/

public class TemperatureReading
{
   // the only instance variable for this class
   private double degreesKelvin;

   // some static variables
   public static final double BOILING_C = 100.0;
   public static final double BOILING_F = 212.0;
   public static final double FREEZING_C = 0.0;
   public static final double FREEZING_F = 32.0;

   // the default constructor
   public TemperatureReading()
   {
      degreesKelvin = 0;
   }

   // another constructor
   public TemperatureReading(double temperature, char scale)
   {
      degreesKelvin = 0; //in case scale is neither C nor F
      if (scale == 'C' )
          setTemperatureC( temperature );
      else if (scale == 'F')
          setTemperatureF( temperature );
      else
          throw new IllegalArgumentException("bad temperature scale");
   }

   // two set methods (mutator methods)
   public void setTemperatureC(double degreesC)
   {
       degreesKelvin = degreesC + 273;
       if ( degreesKelvin < 0 )  // now validate the data
          throw new IllegalArgumentException("bad temperature value");
          // degreesKelvin = 0;
   }

   public void setTemperatureF(double degreesF)
   {
       degreesKelvin = (degreesF - 32)/1.8 + 273;
       if ( degreesKelvin < 0 )  // now validate the data
          throw new IllegalArgumentException("bad temperature value");
          // degreesKelvin = 0;
   }

   // two get methods (accessor methods)
   public double getTemperatureC()
   {
       return degreesKelvin - 273;
   }

   public double getTemperatureF()
   {
       return (degreesKelvin - 273)*1.8 + 32;
   }

   // a simple toString() method
   public String toString()
   {  return "temperature is " + getTemperatureC() + "C or " + getTemperatureF() + "F";
   }

}//TemperatureReading