Write a Temperature class that has two instance variables: a temperature value (
ID: 3530463 • Letter: W
Question
Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have four constructor methods: one for each instance
variable (assume zero degrees if no value is specified and Celsius if no scale is speci- fied), one with two parameters for the two instance variables, and a no-argument constructor (set to zero degrees Celsius). Include the following: (1) two accessor methods to return the temperature
Explanation / Answer
public class Temp
{
double temperature = 0;
String Scale = " ";
/**
* Constructor for objects of class Temp
*/
public Temp(double x,String b)
{
temperature = x;
Scale = "a";
}
public Temp()
{
temperature = 0;
Scale = " ";
}
public double celcius()
{
temperature = 5.0*(temperature - 32)/9.0 ;
return temperature;
}
public double fahrenheit()
{
temperature = (9*(temperature)/5.0) + 32;
return temperature;
}
public double equal()
{
if(x==y)
System.out.println(" The numbers are equal to eachother " );
}
public double greater()
{
}
public double smller()
{
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.