Complete the provided Temperature class You will add any att

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.

Solution

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;

}

}

 Complete the provided Temperature class. You will add any attributes and helper methods as needed. You must complete the constructors and methods in the provid
 Complete the provided Temperature class. You will add any attributes and helper methods as needed. You must complete the constructors and methods in the provid

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site