Question: public class Thermometer { private float currentTemperature = 283.15f; //A default is 283.15 Kelvin public float getTemperature() { return currentTemperature; } } public abstract class

 public class Thermometer { private float currentTemperature = 283.15f; //A default

public class Thermometer {

private float currentTemperature = 283.15f; //A default is 283.15 Kelvin

public float getTemperature() {

return currentTemperature;

}

}

public abstract class Display {

protected Thermometer t;

protected Converter c;

Display(){

c = new Converter();

t = new Thermometer();

}

/**

* Prints the current temperature -- in any unit.

*/

public abstract void displayReading();

}

public class DisplayCelsius extends Display {

/**

* Prints the current temperature - in Celsius.

*/

public void displayReading() {

System.out.println("Displaying: " + c.fromKalvinToCelsius(t.getTemperature()) + "C");

}

}

public class DisplayFahrenheit extends Display {

/**

* Prints the current temperature - in Fahrenheit.

*/

public void displayReading() {

System.out.println("Displaying: " + c.fromKalvinToFahrenheit(t.getTemperature()) + "F");

}

}

public class Refrigerator {

public static void main(String[] args) {

// The following switching needs to take place using strategy.

Display d = new DisplayFahrenheit();

d.displayReading();

d = new DisplayCelsius();

d.displayReading();

}

}

/**

* Temperature converter for your convenience.

*/

public class Converter {

/**

* @param The temperature in Kalvin

* @return The temperature in Fahrenheit

*/

public float fromKalvinToFahrenheit(float a){

return (float) ((a-273.15)*9.0/5.0+32);

}

/**

* @param The temperature in Kalvin

* @return The temperature in Celsius

*/

public float fromKalvinToCelsius(float a){

return (float) (a - 273.15);

}

}

the Fahrenheit and Celsius units are T(Fahrenheit)=(T(Kalvin)273.15)9.0/5.0+32 and T(Celsius)=T(Kalvin)273.15 You have devised an implementation that is based on inheritance, in which you have an abstract Display, specialized according the unit of interest as follows: convenience

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!