you will write the code for a class named Fan to represent a fan. The class contains:   An instance variable named radius that specifies the radius of the fan. An instance variable named on that specifies whether or not the fan is on. Possible values are True and False. An instance variable named speed that represents the speed of the fan. A fan has three speeds indicated with a value 1, 2, or 3. A constructor (i.e., __init__ method) that creates a fan object with parameters for radius, on, and speed. The constructor takes default values of False for on and 1 for speed. An __str__ method that returns a string representation that is different for Fan objects that are on form Fan objects that are off. If the Fan object is off (i.e., value of the instance variable on is False), the string representation should look as follows, where this output assumes that the value of the radius is 5: Fan with radius 5  The fan is currently off If the Fan object is on (i.e., value of the instance variable on is True), the string representation should look as follows, where this output assumes that the value of the radius is 12.5, and the fan is at speed 2: Fan with radius 12.5 The fan is currently on and is running at speed 2 Add accessor (aka getter) methods for all instance variables. Add a mutator (aka setter) method for the instance variable The setOn() method should print an error message if the passed value for on is not True or False. Add a mutator (aka setter) method for the instance variable speed. The setSpeed() method should print an error message if the passed value for speed is not 1, 2, or 3. Moreover, if the setSpeed() method is called when the value of the instance variable for on is False, the method will change the value of that variable to True. I.e., if a user tries to change the speed of an off fan, that will result in turning the fan on.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

you will write the code for a class named Fan to represent a fan. The class contains:

 

  • An instance variable named radius that specifies the radius of the fan.
  • An instance variable named on that specifies whether or not the fan is on. Possible values are True and False.
  • An instance variable named speed that represents the speed of the fan. A fan has three speeds indicated with a value 1, 2, or 3.
  • A constructor (i.e., __init__ method) that creates a fan object with parameters for radius, on, and speed. The constructor takes default values of False for on and 1 for speed.
  • An __str__ method that returns a string representation that is different for Fan objects that are on form Fan objects that are off.


If the Fan object is off (i.e., value of the instance variable on is False), the string representation should look as follows, where this output assumes that the value of the radius is 5:

Fan with radius 5 
The fan is currently off

If the Fan object is on (i.e., value of the instance variable on is True), the string representation should look as follows, where this output assumes that the value of the radius is 12.5, and the fan is at speed 2:

Fan with radius 12.5

The fan is currently on and is running at speed 2

  • Add accessor (aka getter) methods for all instance variables.
  • Add a mutator (aka setter) method for the instance variable The setOn() method should print an error message if the passed value for on is not True or False.
  • Add a mutator (aka setter) method for the instance variable speed. The setSpeed() method should print an error message if the passed value for speed is not 1, 2, or 3. Moreover, if the setSpeed() method is called when the value of the instance variable for on is False, the method will change the value of that variable to True. I.e., if a user tries to change the speed of an off fan, that will result in turning the fan on.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,