Write a class encapsulating the concept of the weather forecast, assuming that i
ID: 3551671 • Letter: W
Question
Write a class encapsulating the concept of the weather forecast, assuming that it has the following attributes: the temperature and the sky conditions, which could be sunny, snowy, cloudy, or rainy. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Temperature, in Fahrenheit, should be between -50 and +150; the default value is 70, if needed. The default sky condition is sunny. Include a method that converts Fahrenheit to Celsius. Celsius temperature = (Fahrenheit temperature
Explanation / Answer
/* OUTPUT
Sky Condition is sunny and temperature is 70.0
Sky Condition is cloudy and temperature is 35.0
is T1 equal to T2 ? Not Equal
Celsius equivalent of 70.0 is 21.11111111111111
is T1 is consistent Consistent
*/
import java.util.*;
//Write a class encapsulating the concept of the weather forecast, assuming that it has the following attributes:
//the temperature and the sky conditions, which could be sunny, snowy, cloudy, or rainy.
class temperature
{
private double Fahrenheit;
private String sky_condition;
//Include a default constructor,
public temperature()
{
//Temperature, in Fahrenheit, should be between -50 and +150; the default value is 70, if needed.
Fahrenheit = 70;
//The default sky condition is sunny.
sky_condition = "sunny";
}
//an overloaded constructor,
public temperature(double f,String s)
{
Fahrenheit = f;
sky_condition = s;
}
//the accessors and
public String getSky_condition()
{
return sky_condition;
}
public double getFahrenheit()
{
return Fahrenheit;
}
//mutators, and methods,
public void setFahrenheit(double f)
{
Fahrenheit = f;
}
public void setSky_condition(String s)
{
sky_condition = s;
}
//toString() and
public String toString()
{
return "Sky Condition is " + sky_condition + " and temperature is " + Fahrenheit;
}
//equals().
public boolean equals(temperature T)
{
return ((Fahrenheit == T.Fahrenheit) && (sky_condition.equalsIgnoreCase(T.sky_condition)));
}
//Include a method that converts Fahrenheit to Celsius. Celsius temperature = (Fahrenheit temperature
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.