Methods For Our Madness :)

Dezzy_Method_To_My_Madness-front-large

Methods For Our Madness

By now, our address book implementation is beginning to take shape.  You have created a Contact class and an AddressBook class, whose main property is our contactlist list.  We have also begun to implement methods, including addContact and importFromCSV. Before moving forward, please make sure those functions are working properly.

Today, we are going to implement a couple more methods in our AddressBook class. For this phase of development, you will need to code two new methods, bubbleSort() and printContactList().

bubbleSort()

Your sort method should implement a bubble sort, which sorts the address book by your contacts’ last names.  (Additionally, if two contacts have the same last name, it should put them in the right order as well, but save that for later.)

printContactList()

This method should print a list of all the contacts by looping through contactlist[].  For now, just include last name, first name, cell phone, and email in the output.

After implementing the functions above as part of the AddressBook class, please use the following main program to test your code.

# *****************************************************
# Main Program
# *****************************************************

# Create a contact
mycontact = Contact("George","Washington", "Geo", "555-1234", "234-1600",
	"gwashington@usa.gov", "PutPhotoHere", "1600 Pennsylvania Ave NW", "Washington",
	"D.C.", "20500")

print "The first President was " + str(mycontact.firstname) + " " + str(mycontact.lastname) + "."
print "His email is " + str(mycontact.email) + "."

# Blank line
print ""

# Create an AddressBook object
myAddressBook = AddressBook('MyAddressBook')

# Add mycontact to AddressBook
myAddressBook.addContact(mycontact)

# Load Contacts from CSV file
myAddressBook.importFromCSVFile('us-500-2.csv')

print ""

# Sort by last name
myAddressBook.bubbleSort()

# Print address list
myAddressBook.printContactList()

Here is an abbreviated sample of the output, which of course should include the 500 contacts sorted in alphabetical order.

The first President was George Washington.
His email is gwashington@usa.gov.

500 contacts added to the AddressBook.

Abdallah Johnetta 919-225-9345 johnetta_abdallah@aol.com
Acey Geoffrey 847-222-1734 geoffrey@gmail.com

...

Wolfgramm Irma 973-545-7355 irma.wolfgramm@hotmail.com
Wolny Lavonna 22102 703-892-2914
Worlds Lorrine 33614 813-863-6467
Wrinkles Nana 10553 914-796-3775
Yaw Audry 813-797-4816 audry.yaw@yaw.org
Yglesias Maurine 53214 414-573-7719
Yori Shawnda 407-538-5106 shawnda.yori@yahoo.com
Yum Dierdre 215-325-3042 dyum@yahoo.com
Zagen Serina 260-273-3725 szagen@aol.com
Zane Sheridan 951-645-3605 sheridan.zane@zane.com
Zepp Vincenza 619-603-5125 vzepp@gmail.com
Zurcher Jerry 321-518-5938 jzurcher@zurcher.org

Once your code is functioning properly, please copy your output to an email and send it to dragonometry@gmail.com. Then, use this submission link to submit your python program as usual.