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.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps