Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
1. Please write the following program in Python 3. Also, please create a UML and write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following...

    THE FOLLOWING PROGRAM IS NEEDED IN JAVA LANGUAGE Design a class torepresent account, include the following members: -Data Members a)Name of depositor-Stringb)Account Number –intc)Type of account –Boolean d)Balance amount -doublee)AnnualInterestrate -double Methods: -(a)To assign initial values (use constructor)(b)To deposit an amount.(c)TO withdraw amount with the restriction the minimum balance is 50 rs. Ifyouwithdraw amount reduced the balance below 50 then print the error message.(d)Display the name and balance of the account.(e)Get_Monthly_intrestRate() -Return the monthly interestrate whichis nothing but Annualintrestrate/12. Annualinterestrate...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

  • C++ FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section:...

    C++ FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section: An integer data field name speed that specifies the speed of the fan (1, 2, 3 or custom) A bool data field named on that specified whether the fan is on by default. A double data field named radius that specifies the radius of the fan A string data field named color that specifies the color of the fan. Public section: - Declare the...

  • Help please 1) Define a Java class for defining the activity of a TV set. The...

    Help please 1) Define a Java class for defining the activity of a TV set. The class contains A private int data field named channel that specifies what channel is currently set for the tuner (channels range from 1 to 120, default is 1) a. b. A private int data field named volumeLevel that specifies the volume level of the TV (range is 1 to 7; default is 1) A private boolean data field named on that determines whether the...

  • New to python if you can add screenshort also, i am using python 3 7.3 (The...

    New to python if you can add screenshort also, i am using python 3 7.3 (The Account class) Design a class named Account that contains A private int data field named id for the account. A private float data field named annualInterestRate that stores the current A constructor that creates an account with the specified id (default 0), initial The accessor and mutator methods for id, balance, and annualInterestRate A private float data field named balance for the account. interest...

  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT