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

JAVA code only (Please look at the attached output!!!!!!) Write a class encapsul

ID: 3810422 • Letter: J

Question

JAVA code only (Please look at the attached output!!!!!!)

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 - 32) * 5/9. Also include a method that checks whether the weather attributes are consistent (there are two cases where they are not consistent: when the temperature is below 32 and it is not snowy, and when the temperature is above 100 and it is not sunny). Write a client class to test all the methods in your class.

Here is the needed output

s Javadoc Declaration G Console

Explanation / Answer

WeatherForecast.java

public class WeatherForecast {
   //Declaring variables
private double temperarture;
private String skyCondition;
  
   //Zero argumented constructor

public WeatherForecast() {
   super();
   this.temperarture = 70.0;
   this.skyCondition = "Sunny";
}
//Parameterized constructor


public WeatherForecast(double temperarture, String skyCondition) {
   super();
   setTemperarture(temperarture);
   setSkyCondition(skyCondition);
}
//getters and setters
public double getTemperarture() {
   return temperarture;
}
public void setTemperarture(double temperarture) {
   if(temperarture>=-50 && temperarture<=150)
   this.temperarture = temperarture;
   else
   {
   System.out.println("Temperature Cannot be less than -50 or greater than 150.");
   setTemperarture(70.0);
   System.out.println("Temperature set to 70.0");
   }
}


public String getSkyCondition() {
   return skyCondition;
}
public void setSkyCondition(String skyCondition) {
this.skyCondition=skyCondition;
}

@Override
public boolean equals(Object obj) {
   if (this == obj)
       return true;
   if (obj == null)
       return false;
   if (getClass() != obj.getClass())
       return false;
   WeatherForecast other = (WeatherForecast) obj;
   if (skyCondition == null) {
       if (other.skyCondition != null)
           return false;
   } else if (!skyCondition.equals(other.skyCondition))
       return false;
   if (Double.doubleToLongBits(temperarture) != Double
           .doubleToLongBits(other.temperarture))
       return false;
   return true;
}
  
//This method convert fahrenheit to celsius
public double ConvertfahrenToCelsius(double ftemp)
{
   return (ftemp - 32) * (5.0/9);
}

//Checking whether the info is consistant or not
public void isConsistant()

{
if(temperarture<32 && !skyCondition.equals("snowy"))
{
   System.out.println(skyCondition+" is not consistant.");
}

else if(temperarture<100 && !skyCondition.equals("sunny"))
{
   System.out.println(skyCondition+" is not consistant.");
}
else
{
   System.out.println(skyCondition+" is consistant.");
}
  
}
@Override
public String toString() {
   return "Temperarture=" + temperarture + " Sky Condition="+ skyCondition;
}


}

___________________

Client.java

public class Client {


   public static void main(String[] args) {
       //Creating WeatherForecaset class object1
       WeatherForecast wf1=new WeatherForecast();
       System.out.println("Weather Forecast#1 object info"+wf1.toString());

       //Creating WeatherForecaset class object2
       WeatherForecast wf2=new WeatherForecast(65.0,"cloudy");
       System.out.println("Weather Forecast#2 object info"+wf2.toString());
      
  
       //modifying values
       wf2.setSkyCondition("rainy");
       wf2.setTemperarture(60);
      

       System.out.println(" -------- After Modifying Weather Forecast#2 object --------");
       System.out.println("Weather Forecast#2 object info"+wf2.toString());
      
       System.out.printf(" After converting 80F to celsius :%.2f ",wf2.ConvertfahrenToCelsius(80));

       //Creating WeatherForecaset 3 class object
       WeatherForecast wf3=new WeatherForecast(90,"sunny");
       boolean bool=wf3.equals(wf2);
       if(bool)
       {
           System.out.println("WeatherForecast#3 and WeatherForecast#1 are equal");
       }
       else
       {
           System.out.println("WeatherForecast#3 and WeatherForecast#1 are different");
       }
      
       System.out.print("Checking whether weatherForecase#3 is consistant or not :");
       wf3.isConsistant();
      

   }

}

___________________

Output:

Weather Forecast#1 object infoTemperarture=70.0 Sky Condition=Sunny
Weather Forecast#2 object infoTemperarture=65.0 Sky Condition=cloudy

-------- After Modifying Weather Forecast#2 object --------
Weather Forecast#2 object infoTemperarture=60.0 Sky Condition=rainy

After converting 80F to celsius :26.67
WeatherForecast#3 and WeatherForecast#1 are different
Checking whether weatherForecase#3 is consistant or not :sunny is consistant.

___________Thank You