Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class that represents a person’s contact information using PYTHON. A co

ID: 3779323 • Letter: C

Question

Create a class that represents a person’s contact information using PYTHON. A contact has a first name, last name, phone number, address, city, state and zip-code, all of which are private. Make get and sets methods to access to the data members. Make a __str__ method. In your main, create a list of contacts. Read in all of the contacts from the addresses.txt file and add them to the list. Then allow the user to choose from different menu options to display and modify the list of contacts. Then allow the user to choose from a list of functions: 1. Create and add a new contact to the list.

a. Prompt the user to enter all of the contact info for a person.

2. Search for a person and display all of the information stored on them. If there are multiple people in the list with the same search information, display all of them.

a. by Last Name b. by Zip-Code

3. Alter a person by first searching for them in the list, and then allowing the user to overwrite their information.

a. Find by First and Last Name, then display a menu that allows the user to enter any information available. Repeat this menu until they are done.

4. Display the total number of contacts.

5. Display all contacts in a formatted list. When the user quits the program, write the contents of the list back to the file. When the file is opened, you should overwrite the existing text (ie. not append), to make sure all of the updates are made.

Example Output: Rolodex

Menu: 1. Add Contact

2. Search for Contact

3. Modify Contact

4. Display Number of Contacts

5. Display All Contacts

6. Quit

1 Enter First Name: Lisa

Enter Last Name: Simpson

Enter Phone Number: 555-1212

Enter Address: 742 Evergreen Terrace

Enter City: Springfield

Enter State: OR Enter Zip: 90122

Explanation / Answer

code:

class Contact:

def __init__(self):
self.__firstName = None;
self.__lastName = None;
self.__phoneNumber = None;
self.__city = None;
self.__state = None;
self.__zipCode = None;
self.__address = None;
def set_firstname(self,firstName):
self.__firstName = firstName;

def get_firstname(self):
return self.__firstName;

def set_lastname(self,lastName):
self.__lastName = lastName;

def get_lastname(self):
return self.__lastName;

def set_phoneNumber(self,phoneNumber):
self.__phoneNumber = phoneNumber;

def get_phoneNumber(self):
return self.__phoneNumber;

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

def get_address(self):
return self.__address;

def set_city(self,city):
self.__city = city;

def get_city(self):
return self.__city;

def set_state(self,state):
self.__state = state;

def get_state(self):
return self.__state;

def set_zipCode(self,zipCode):
self.__zipCode = zipCode;

def get_firstname(self):
return self.__zipCode;

def __str__(self):
return self.__firstName,self.__lastName,self.__phoneNumber,self.__address,self.__city,self.__state,self.__zipCode;

fo = open("C:/Users/jntuk/Desktop/Project/chegg/contacts.txt", "r+")
contacts = []
for line in fo:
contacts.append(line)
option = 1;
while(option>=1 & option<=6):
print("1.Add Contact");
print("2. Search for Contact");
print("3. Modify Contact");
print("4. Display Number of Contacts");
print("5. Display All Contacts");
print("6.Quit")
option = input("");
option = int(option);
if option == 1 :
firstName = input("Enter First Name:");
lastName = input("Enter Last Name:");
phoneNumber = input("Enter Phone Number:");
address = input("Enter Address:");
city = input("Enter City:");
state = input("Enter State:");
zipCode = input("Enter Zip:");
c = Contact();
c.set_firstname(firstName);
c.set_lastname(lastName);
c.set_phoneNumber(phoneNumber);
c.set_address(address);
c.set_city(city);
c.set_state(state);
c.set_zipCode(zipCode);
contacts.append(c);
elif option == 2 :
firstName = input("Enter First Name:");
persons = [];
for contact in contacts:
details = contact.split(",");
if firstName is details[0]:
persons.append(contact);

if len(persons) == 0:
print(firstName,"is not available in the contact list.");
elif len(persons) == 1:
print(persons);
else:
print("a. by Last Name");
print("b. by Zip-Code");
s = input("");
if s in "a":
print
elif s in "b":
print
else:
print("Wrong selection.Please select correct option.");
  
  
elif option == 3 :
print
  

elif option == 4 :
print("Total number of contacts : ",len(contacts));
elif option == 5 :
for contact in contacts :
print(contact);
elif option == 6 :
for contact in contacts:
fo.write(contact);
fo.close();
exit;
else:
print("Wrong selection.Please select correct option.");
  
  
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote