Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

Id already thrown away the receipt.

Answered: 1 week ago