Write the definition of a class WeatherForecast that provides the following behavior (methods): A method called set_skies that has one parameter, a String. A method called set_high that has one parameter, an int. A method called set_low that has one parameter, an int. A method called get_skies that has no parameters and that returns the value that was last used as an argument in set_skies. A method called get_high that has no parameters and that returns the value that was last used as an argument in set_high. A method called get_low that has no parameters and that returns the value that was last used as an argument in set_low. No constructor need be defined. Be sure to define instance variables as needed by your "get"/"set" methods.

Respuesta :

Answer:

class WeatherForecast(object):

 

skies = ""

min = 0

max = 0

 

def get_skies(self):

return self.skies

def set_skies(self, value):

self.skies = value

def get_max(self):

return self.max

 

def set_max(self, value):

self.max = value

 

def get_min(self):

return self.min

def set_min(self, value):

self.min = value

def main():

obj1 = WeatherForecast()

obj1.set_skies("Skies1")

obj1.set_max(2)

obj1.set_min(0)

print("Calling get_skies(): ", obj1.get_skies())

print("Calling get_max(): ", obj1.get_max())

print("Calling get_min(): ", obj1.get_min())

main()

Explanation:

  • Inside the WeatherForecast class, initialize variables for skies, minimum and maximum.
  • Define the getter and setter method for the necessary variables inside the WeatherForecast class.
  • Create an object of the class WeatherForecast.
  • Call the getter functions of  the class and display the results.
  • Finally call the main function to test the program.
ACCESS MORE