Question

[python3] Start by using UML and planning the functionality of each method (including the constructor, that...

[python3]

Start by using UML and planning the functionality of each method (including the constructor, that is, the __init__() method)

Initialization of your objects must require at least one parameter (in addition to self)

All of your objects attributes/fields should be 'private' and you should include getters and setters for each attribute/field

You must be able to print your object in a meaningful way and you should define what it means for two objects to be equal

Additionally, your object must do one trick (e.g., generate a random number or change color)

Implement a Class in Python for your newly designed object

Create three objects: two that are equal and one that is not and show that this is true

.

Make it as easy as possible please.

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

class Complex:

    # constructor

    def __init__(self, real = 0, imag = 0):

   

        self.real = real

        self.imag = imag

       

    # setter method

    def setReal(self, real):

   

        self.real = real

       

    def setImaginary(self, imag):

   

        self.imag = imag

       

    # getter method

    def getReal(self):

   

        return self.real

       

    def getImaginary(self):

   

        return self.imag

       

    # overload == operator

    def __eq__(self, ob):

   

      return self.real == ob.getReal() and self.imag == ob.getImaginary()

       

    def __str__(self):

   

        return '( ' + str( self.real ) + ' , ' + str( self.imag ) + ' )'

       

ob1 = Complex( 2 , 3 )

ob2 = Complex( 2 , 3 )

ob3 = Complex( 4 , 8 )

print('ob1 : ' + str(ob1))

print('ob2 : ' + str(ob2))

print('ob3 : ' + str(ob3))

print('Is ob1 equal to ob2 : ' , ob1 == ob2 )

print('Is ob1 equal to ob3 : ' , ob1 == ob3 )

Sample Output

UML Diagram

real: float imag: float setReal(real): void setlmaginary(imag): void getReal): float getlmaginary):float -eq_():boolean

Add a comment
Know the answer?
Add Answer to:
[python3] Start by using UML and planning the functionality of each method (including the constructor, that...
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
  • Please use python Programming Language: Select one of the following topics: Band Character Account Create a...

    Please use python Programming Language: Select one of the following topics: Band Character Account Create a class based on your chosen topic. Make sure to include at least four attributes of varying types, a constructor, getters/setters for each attribute w/input validation, a toString, a static attribute, and a static method. Then, create a function (outside of your class) that connects to a text file which should contain the attributes of several objects. Read the data from the file, use the...

  • Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def...

    Python 3> Make a class called BMW: Parameterized constructor with three instance variables (attributes): Hint: def __init__(self, make, model, year) Methods in BMW parent class (can leave as method stubs for now): startEngine() -must print "The engine is now on." stopEngine() -must print "The engine is now off." Make another class called ThreeSeries -Must inherit BMW Hint: class ThreeSeries(BMW): -Also passes the three attributes of the parent class and invoke parent Hint: BMW.__init__(self, cruiseControlEnabled, make, model, year) -Constructor must have...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Open Visual Paradigm for UML. File | New Project. Set the Project name to {FLname}MyCompanyDesign, where...

    Open Visual Paradigm for UML. File | New Project. Set the Project name to {FLname}MyCompanyDesign, where {FLname} is replaced by the first letter of your first name plus your last name. E.g. if your name is Maria Marciano, your project name must be MMarcianoMyCompanyDesign. Click the Create Blank Project button. Save the .vpp file in the root of your Eclipse project directory. File | Save As... Use the ... button to navigate to the root of your Eclipse project directory....

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

  • Lab 10C - Creating a new class This assignment assumes that you have read and understood...

    Lab 10C - Creating a new class This assignment assumes that you have read and understood the following documents: http://www.annedawson.net/Python3_Intro_OOP.pdf http://www.annedawson.net/Python3_Prog_OOP.pdf and that you're familiar with the following example programs: http://www.annedawson.net/python3programs.html 13-01.py, 13-02.py, 13-03.py, 13-04.py Instructions: Complete as much as you can in the time allowed. Write a Python class named "Car" that has the following data attributes (please create your own variable names for these attributes using the recommended naming conventions): - year (for the car's year of manufacture)...

  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

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