Question

In python Create a class that holds personal data: name, address, age, and phone number. Write...

In python

Create a class that holds personal data: name, address, age, and phone number. Write the

necessary get (accessor) and set mutator methods. Also include a program that creates three instances

of the class. This could be you and 2 friends or 2 family members.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class PersonalData:
    def __init__(self, name='', address='', age=0, phone_number=''):
        self.name = name
        self.address = address
        self.age = age
        self.phone_number = phone_number

    def get_name(self):
        return self.name

    def get_address(self):
        return self.address

    def get_age(self):
        return self.age

    def get_phone_number(self):
        return self.phone_number

    def set_name(self, name):
        self.name = name

    def set_address(self, address):
        self.address = address

    def set_age(self, age):
        self.age = age

    def set_phone_number(self, phone_number):
        self.phone_number = phone_number


p1 = PersonalData()
p1.set_name('ronaldo')
p1.set_age(34)
p1.set_address('portugal')
p1.set_phone_number('777-777-7777')
p2 = PersonalData()
p2.set_name('messi')
p2.set_age(32)
p2.set_address('argentina')
p2.set_phone_number('100-100-1010')
p3 = PersonalData()
p3.set_name('bale')
p3.set_age(30)
p3.set_address('wales')
p3.set_phone_number('111-111-1111')
print("Name: {}, Address: {}, Age: {}, Phone Number: {}".format(p1.get_name(), p1.get_address(), p1.get_age(), p1.get_phone_number()))
print("Name: {}, Address: {}, Age: {}, Phone Number: {}".format(p2.get_name(), p2.get_address(), p2.get_age(), p2.get_phone_number()))
print("Name: {}, Address: {}, Age: {}, Phone Number: {}".format(p3.get_name(), p3.get_address(), p3.get_age(), p3.get_phone_number()))

Add a comment
Know the answer?
Add Answer to:
In python Create a class that holds personal data: name, address, age, and phone number. 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
  • using python to Design a class that holds the following personal data: name, address, age, and...

    using python to Design a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods. Also, write a program that creates three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.

  • PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1...

    PLEASE YOU PYTHON 3 TO SOLVE! THANKS! PLEASE YOU PYTHON 3 TO SOLVE! THANKS! Example 1 Design a class named Information that holds the following personal data: .name, age, address (this attribute has a default value of “unknown"), and phone number. . All the attributes are defined as private. • Write appropriate accessor and mutator methods. • Complete the definition of the str_ method, such that it displays each Information object's data in the following format: name: "Sarah Jones” –...

  • Write a Python class, Circle, constructed by a radius and two methods which will compute the...

    Write a Python class, Circle, constructed by a radius and two methods which will compute the area and the perimeter of a circle. Include the constructor and other required methods to set and get class attributes. Create instances of Circle and test all the associated methods. Write a Python class, Rectangle, constructed by length and width and a method which will compute the area of a rectangle. Include the constructor and other required methods to set and get class attributes....

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    Design a class named Person with fields for holding a person's name, address, and telephone number (all as Strings). Write a constructor that initializes all of these values, and mutator and accessor methods for every field. Next, design a class named Customer, which inherits from the Person class. The Customer class should have a String field for the customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write a constructor that initializes...

  • Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class...

    Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.

  • Write a Python program that creates a class which represents a candidate in an election. The...

    Write a Python program that creates a class which represents a candidate in an election. The class must have the candidates first and last name, as well as the number of votes received as attributes. The class must also have a method that allows the user to set and get these attributes. Create a separate test module where instances of the class are created, and the methods are tested. Create instances of the class to represent 5 candidates in the...

  • 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,...

  • Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person’s name and...

    Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList Copyright | Addison-Wesley | Starting Out with Java | [email protected] | Printed from Chegg iOS App

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using JAVA* Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator...

  • C++ Question Create the ADT of the Phone class. Phone uses three integer variables that describe...

    C++ Question Create the ADT of the Phone class. Phone uses three integer variables that describe a phone number. Example: Part1: 123, Part2: 456, Part3: 0001 describes the phone number (123)456-0001. Also, add to the Phone ADT class any constructor, any accessor and any mutator function that you may find helpful. Also, add the precondition and postcondition of each function. If you could add comments to explain what you are doing that would be very helpful, but not necessary. Thank...

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