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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education