Write the definition of a class WeatherForecast that provides the following behavior (methods): A method called setSkies that has one parameter, a String. A method called setHigh that has one parameter, an int. A method called setLow that has one parameter, an int. A method called getSkies that has no parameters and that returns the value that was last used as an argument in setSkies. A method called getHigh that has no parameters and that returns the value that was last used as an argument in setHigh. A method called getLow that has no parameters and that returns the value that was last used as an argument in setLow. No constructor need be defined. Be sure to define instance variables as needed by your “get”/”set” methods — initialize all numeric variables to 0 and any String variables to the empty string.

Write the definition of a class WeatherForecast that provides the following behavior (methods): A method called setSkies that has one parameter, a String. A method called setHigh that has one parameter, an int. A method called setLow that has one parameter, an int. A method called getSkies that has no parameters and that returns the value that was last used as an argument in setSkies. A method called getHigh that has no parameters and that returns the value that was last used as an argument in setHigh. A method called getLow that has no parameters and that returns the value that was last used as an argument in setLow. No constructor need be defined. Be sure to define instance variables as needed by your “get”/”set” methods — initialize all numeric variables to 0 and any String variables to the empty string.

LANGUAGE: JAVA

CHALLENGE:

Write the definition of a class WeatherForecast that provides the following behavior (methods):
A method called setSkies that has one parameter, a String.
A method called setHigh that has one parameter, an int.
A method called setLow that has one parameter, an int.
A method called getSkies that has no parameters and that returns the value that was last used as an argument in setSkies.
A method called getHigh that has no parameters and that returns the value that was last used as an argument in setHigh.
A method called getLow that has no parameters and that returns the value that was last used as an argument in setLow.
No constructor need be defined. Be sure to define instance variables as needed by your “get”/”set” methods — initialize all numeric variables to 0 and any String variables to the empty string.

SOLUTION:


public class WeatherForecast{
   private String skies = "";
   private int high = 0;
   private int low = 0;
   public void setSkies(String theSkies){
      skies = theSkies;
   }

   public void setHigh(int theHigh){
      high = theHigh;
   }
   
   public void setLow(int theLow){
      low = theLow;
   }

   public String getSkies(){
      return skies;
   }

   public int getHigh(){
      return high;
   }

   public int getLow(){
      return low;
   }
}

Add comment