Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the provided Temperature class. You will add any attributes and helper

ID: 3926293 • Letter: C

Question

Complete the provided Temperature class. You will add any attributes and helper methods as needed. You must complete the constructors and methods in the provided class (without changing any signatures or return types). In this problem you need to the able to convert temperatures between Celsius. Fahrenheit and Kelvin. For help, sec https://en.vikip6dia.org/wiki/Conversion_of_units_of_temperature. A temperature object keeps track of which scale it is currently using outputs its temperature value in that scale whenever asked. The scale can be changed at any time.

Explanation / Answer

public class Temperature

{

private double t;

private char scale;

Temperature(double t)

{

this.t=t;

this.scale='C';

}

Temperature(double t,char s)

{

this.t=t;

this.scale=s;

}

public void setScale(char s)

{

if(scale==s)

{

this.t=t;

}

else if(scale=='C'&&s=='K')

t=t+273.15;

else if(scale=='C'&&s=='F')

t=t+32.0;

else if(scale=='K'&&s=='F')

t=t-459.67;

else if(scale=='K'&&s=='C')

t=t-273.15;

else if(scale=='F'&&s=='K')

t=t+459.67;

else if(scale=='F'&&s=='C')

t=t-32.0;

}

public char getScale()

{

return this.scale;

}

public double getTemp()

{

return this.t;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote