1 answer

1. Please write the following program in Python 3. Also, please create a UML and write...

Question:

1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs.

(The Fan class) Design a class named Fan to represent a fan. The class contains:

Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed.

A private int data field named speed that specifies the speed of the fan.

A private bool data field named on that specifies whether the fan is on (the default is False).

A private float data field named radius that specifies the radius of the fan.

A private string data field named color that specifies the color of the fan.

The accessor and mutator methods for all four data fields.

A constructor that creates a fan with the specified speed (default SLOW), radius (default 5), color (default blue), and on (default False).

Draw the UML diagram for the class and then implement the class. Write a test program that creates two Fan objects. For the first object, assign the maximum speed, radius 10, color yellow, and turn it on. Assign medium speed, radius 5, color blue, and turn it off for the second object.Display each object’s speed, radius, color, and on properties.


Answers

Hello,

Here is the code for class FAN in Python 3, and also UML diagram attahced below this code.

I have provide the in-line comments inside the code to make it slef explanatory and UML diagram is easy to understand:

#To execute the code you must have python installed on your machine and copy paste this code to editor and save thee file with .py extension. Then go to command promt and navigate to the directory where your file is present. Once you are in the same directory where is your .py file execute the code by followinf command:

python abc.py (where abc is the name of the file)

************************Python 3 Code Start*********************************

#Creating a FAN Class with accessor and mutator methods for speed,on,radius and color

class FAN():

#main code to hold the constant values

def __init__(self):

self.__my_attr_speed = 2

self.__my_attr_on = "False"

self.__my_attr_radius = 5

self.__my_attr_color = "Blue"

#This is accessor for all four attributes

def set_my_attr_speed(self,speed,on,radius,color):

self.__my_attr_speed = speed

self.__my_attr_on = on

self.__my_attr_radius = radius

self.__my_attr_color = color

#This is mutator method for all four attributes

def get_my_attr_speed(self):

return str(self.__my_attr_speed) + "," + str(self.__my_attr_on) + "," + str(self.__my_attr_radius) + "," + str(self.__my_attr_color)

#Initiatilizing the Program with three constant.

print("\n******* FAN CLass ******\n Speed constant\n 1. SLOW \n 2. MEDIUM \n 3.

FAST")

#Creating first object to print the default values

myObject = FAN()

print("\nDefault values:\n")

print (myObject.get_my_attr_speed())

print("\n****************************")

print("\nFirst FAN object with maximum speed, radius 10, color yellow, and on:\n")

#Creating second object to print the default values

myObject1 = FAN()

#Initatializing the constructor with follwing values

myObject1.set_my_attr_speed(3,"True",10,"Yellow")

print (myObject1.get_my_attr_speed())

print("\n****************************")

print("\nSecond FAN object with medium speed, radius 5, color blue, and off:\n")

#Creating third object to print the default values

myObject2 = FAN()

#Initatializing the constructor with follwing values

myObject2.set_my_attr_speed(1,"False",5,"Blue")

print (myObject2.get_my_attr_speed())

************************Python 3 Code End*********************************

UML Diagam:

Hope you find helpful.

Thanks

.

Similar Solved Questions

1 answer
C Classes TR Download and Wat. Configuring a mail. Registration for the Linux Distribe OCHEMICAL BONDING...
C Classes TR Download and Wat. Configuring a mail. Registration for the Linux Distribe OCHEMICAL BONDING Predicting the single-bonded molecular compounds formed by t.. For each row In the table below, decide whether the pair of elements will form a molecular compound held together by covalent chemic...
1 answer
Homework: Ch 13 Homework Score: 0 of 8 pts P13-38A (similar to) Save 2 of 2...
Homework: Ch 13 Homework Score: 0 of 8 pts P13-38A (similar to) Save 2 of 2 (1 complete) D HW Score: 4.2496, 0.64 of 15 pts EQuestion Help Dearborn Manufacturing Co. completed the tollowing transactions during 2016 (Click the icon to view the transactions) Requirements 1. Record the transactions in ...
1 answer
What are some behaviors that show infants are capable of learning? How does imitation differ in...
What are some behaviors that show infants are capable of learning? How does imitation differ in newborns and older infants? What is habituation?...
1 answer
When we re sampling with replacement, that means the events are mutually exclusive. " True False
When we re sampling with replacement, that means the events are mutually exclusive. " True False...
1 answer
B Two blocks of masses ma 1.8 kg and mp 3.5 kg can slide one relative...
B Two blocks of masses ma 1.8 kg and mp 3.5 kg can slide one relative to one another, depending on the magnitude of the applied force P. The coefficient of friction between blocks A and B as well as between block B and the horizontal surface is 0.3. Case a: assume that the system is just on the verg...
1 answer
Is the 2019 Business Roundtable Statement (BRS) redefining the purpose of corporations likely to make any...
Is the 2019 Business Roundtable Statement (BRS) redefining the purpose of corporations likely to make any difference to boards of directors and to activists?...
1 answer
5. Number of days' n receivables, 18.3 EXCEL TEMPLATE Obj. 3, 4,5 PR 14-4A Measures of...
5. Number of days' n receivables, 18.3 EXCEL TEMPLATE Obj. 3, 4,5 PR 14-4A Measures of liquidity, solvency, and profitability The comparative financial statements of Marshall Inc, are as follows. The market price of Marshall common stock was $82.60 on December 31, 20Y2. Marshall Inc. Comparative...
1 answer
Suppose that the average U.S. household uses 14600 kWh (kilowatt-hours) of energy in a year. If...
Suppose that the average U.S. household uses 14600 kWh (kilowatt-hours) of energy in a year. If the average rate of energy consumed by the house was instead diverted to lift a 2130 kg car 11.3 m into the air, how long would it take? Number Using the same rate of energy consumption, how long would it...
1 answer
You have to be very detailed and write clear! ENGINEERING ECONOMY MFE 4720 HOMEWORK #11 NAME...
you have to be very detailed and write clear! ENGINEERING ECONOMY MFE 4720 HOMEWORK #11 NAME 1) An unmarried engineer earns a gross income of $120,000 for various projects executed during the year. one $3,000 exemption and estimated itemi zed deduction of $15,000. deductions (standard). Use the 201x...
1 answer
The asymptotic Bode plot shown below represents a lowpass filter-amplifier with a break frequency of ....
The asymptotic Bode plot shown below represents a lowpass filter-amplifier with a break frequency of . Design a circuit to be connected in cascade with the amplifier such that the break frequency is extended to . wn1000rads A, dB 20 dB -40 dB/decade rad/s 1000 wn5000rads A, dB 20 dB -40 dB/decad...
1 answer
Question 34 2 pts variability may also be thought of as Within-groups; 'error Between-groups; 'significant' Between-groups;...
Question 34 2 pts variability may also be thought of as Within-groups; 'error Between-groups; 'significant' Between-groups; 'error' Within-groups: 'effect'...
1 answer
A 100 gm ball strikes a wall at 600 (with respect to the wall) with a...
A 100 gm ball strikes a wall at 600 (with respect to the wall) with a velocity of 8 m/sec and bounces back with three forth of its speed at the same angle with respect to the wall. If the ball remains in contact for 0.1 sec, what is the force? A 100 gm ball strikes a wall at 60° (with respect ...
1 answer
An object with a mass of #8 kg# is on a plane with an incline of #pi/8 #. If the object is being pushed up the plane with # 12 N # of force, what is the net force on the object?
An object with a mass of #8 kg# is on a plane with an incline of #pi/8 #. If the object is being pushed up the plane with # 12 N # of force, what is the net force on the object?...
1 answer
Objective Knowteage Check A solution is prepared at 25 C that is initially 0.23 M in...
Objective Knowteage Check A solution is prepared at 25 C that is initially 0.23 M in chlorous acid (HCIO,), a weak acid with K-1.1 x 10,and 0.23 M in sodium chlorite (NaCI0,) Calculate the pH of the solution. Round your answer to 2 decimal places. pH- X...
1 answer
233 An auto manufacturer claims that its new 4-cylinder Hybrid auto with manual shift averages 50...
233 An auto manufacturer claims that its new 4-cylinder Hybrid auto with manual shift averages 50 mpg under city driving conditions. A Federal Agency believes this claim is too high and decides to randomly test 25 of the manufacturer's 4-cylinder Hybrid autos with manual shift. The Agency determ...
1 answer
(A) Do you think that exports of oil from Alberta will result in a higher, sustainable...
(A) Do you think that exports of oil from Alberta will result in a higher, sustainable standard of living for Canadians? Explain your answer with reference to Canada’s economic history, the Staples Thesis and the Resource Curse. (B) Would Canada’s prospects for an improved standard of li...