In some situations, a class needs the help of other classes to complete a task. These other classes are called collaborators. In this program, it is necessary to compare temperatures. However, temperatures may be expressed using different scales, such as Fahrenheit or Celsius. You will use a collaborator class to handle converting temperatures from one scale to another.

Complete the Temperature class below. Use two instances of the Converter to convert to Celsius or Fahrenheit in the compareTo method.

Complete the following file:

Temperature.java

/** Temperature class represents a specific temperature value in a specific scale. */ public class Temperature { private String scale; private double value; private static Converter toCelsius = ... private static Converter toFahrenheit = ... /** Constructs a temperature. @param aValue the temperature value in the given scale @param aScale "C" for Celsius, "F" for Fahrenheit */ public Temperature(double aValue, String aScale) { value = aValue; scale = aScale; } public String getScale() { return scale; } public double getValue() { return value; } /** Compares two temparatures. @param other another Tempeature object to be compared with this one @return -1 if the other object's value is larger than this object's value 0 if the values are equal 1 if the other object's value is smaller than this object's value. */ public int compareTemps(Temperature other) { // Use the appropriate converter so that you can compare the values } }

Use the following files:

Converter.java

/**
   Converts from one unit to another. The converted value is computed
   as scaleFactor * originalValue + offset. For example, to convert Celsius to
   Fahrenheit, the scale factor is 9.0/5, and the offset is 32.
*/
public class Converter
{
   private double scaleFactor;
   private double offset;
   
   /**
      Constructs a converter with a given scale factor and offset.
      @param scaleFactor the scale factor
      @param offset the offset
   */
   public Converter(double scaleFactor, double offset)
   {
      this.scaleFactor = scaleFactor;
      this.offset = offset;
   }


   /**
      Converts a value.
      @param value the original value
      @return the converted value
   */
   public double convert(double value)
   {
      return scaleFactor * value + offset;
   }
}

TemperatureChecker.java

public class TemperatureChecker
{
   public int check(double t1, String unit1, double t2, String unit2)
   {
      Temperature temp1 = new Temperature(t1, unit1);
      Temperature temp2 = new Temperature(t2, unit2);
      return temp1.compareTo(temp2);
   }
}