1. Write a Python program that performs as a Tuffy Titan Contacts phone list. You are given the main.py file and are required to create the Contacts class. 2. The following is the Entity-Relationship Diagram for the data structure: Entity-Relationship Diagram contacts contact_id first_name last_name 1. The following is some sample data to help visualize the data model: Sample Data Phone Numbers Home: (224)965-7800 Cell: (113)290-9210 Home: (227)673-8398 Work: (726)114-4178 Cell: (488)190-7360 Cell: (388)897-6231 Work: (675)903-1290 Cell: (747)582-9543 Home: (370)737-9472 Business: (605)101-7583 Contact Anna Kendrick Rebel Wilson Skylar Astin Adam DeVine phones phone_id contact_id phone_type phone_number 1. Create a Contacts class to meet the following requirements: i. Create a file named contacts.py. a. Define a method named __init___ to meet the following requirements: a. Declare a class variable to store the database file and intitialize it to an empty string. b. Define a method named set_database_name to meet the following requirements: a. Take a database file name as a positional parameter and assign the value to the class variable. b. If the file already exists, do nothing (we want to preserve any data in the file for continued use.) c. If the file does not exisit, connect to the sqlite3 file and create the contacts table and the phones table using the proper SQL CREATE TABLE statement. Use the same field names as those used in the Entity-Relationship diagram above. Use integers for all the id's and text for all the other data.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
c = contacts.Contacts()
   
  while True:
  print(" *** TUFFY TITAN CONTACTS MAIN MENU")
  print()
  print("1. Set database name")
  print("2. Add contact")
  print("3. Modify contact")
  print("4. Add phone")
  print("5. Modify phone")
  print("6. Print contact phone list")
  print("9. Exit the program")
  print()
  choice=int(input("Enter menu choice: "))
  print()
   
  # set database name
  ifchoice==1:
  database_name=input("Enter database name: ")
  c.set_database_name(database_name)
  print()
   
  # add contact
  elifchoice==2:
  database_name=c.get_database_name()
  ifdatabase_name=='':
  print('ERROR: Set database name')
  print()
  else:
  first_name=input("Enter first name: ")
  last_name=input("Enter last name: ")
  c.add_contact(first_name, last_name)
  print()
   
  # modify contact
  elifchoice==3:
  database_name=c.get_database_name()
  ifdatabase_name=='':
  print('ERROR: Set database name')
  print()
  else:
  contact_id=input("Enter contact id: ")
  first_name=input("Enter first name: ")
  last_name=input("Enter last name: ")
  c.modify_contact(contact_id, first_name, last_name)
  print()
   
  # add phone
  elifchoice==4:
  database_name=c.get_database_name()
  ifdatabase_name=='':
  print('ERROR: Set database name')
  print()
  else:
  contact_id=input("Enter contact id: ")
  phone_type=input("Enter phone type: ")
  phone_number=input("Enter phone number: ")
  c.add_phone(contact_id, phone_type, phone_number)
  print()
   
  # modify phone
  elifchoice==5:
  database_name=c.get_database_name()
  ifdatabase_name=='':
  print('ERROR: Set database name')
  print()
  else:
  phone_id=input("Enter phone id: ")
  phone_type=input("Enter phone type: ")
  phone_number=input("Enter phone number: ")
  c.modify_phone(phone_id, phone_type, phone_number)
  print()
   
  # print report
  elifchoice==6:
  database_name=c.get_database_name()
  ifdatabase_name=='':
  print('ERROR: Set database name')
  print()
  else:
  list=c.get_contact_phone_list()
  print('=======================================================')
  print('(id) Contact (id) Phone Numbers ')
  print('======================= ==============================')
  previous_id=0
  forxinlist:
  ifx[0] ==previous_id:
  print(f'{"":5}{" ":20}{"("+str(x[3])+")":5}{x[5]+": "+x[6]:25}')
  else:
  print(f'{"("+str(x[0])+")":5}{x[1]+" "+x[2]:20}{"("+str(x[3])+")":5}{x[5]+": "+x[6]:25}')
  previous_id=x[0]
  print('=======================================================')
  print()
   
  #EXIT
  elifchoice==9:
  break;
1. Write a Python program that performs as a Tuffy Titan Contacts phone list. You are given the main.py file and
are required to create the Contacts class.
2. The following is the Entity-Relationship
contacts
contact_id
first_name
last_name
Diagram for the data structure:
Entity-Relationship Diagram
Contact
Anna Kendrick
1. The following is some sample data to help visualize the data model:
Rebel Wilson
Skylar Astin
Adam DeVine
phones
phone_id
contact_id
phone_type
phone_number
1. Create a Contacts class to meet the following requirements:
i. Create a file named contacts.py.
Sample Data
Phone Numbers
Home: (224)965-7800
Cell: (113)290-9210
Home: (227)673-8398
Work: (726)114-4178
Cell: (488)190-7360
Cell: (388)897-6231
Work: (675)903-1290
Cell: (747)582-9543
Home: (370)737-9472
Business: (605)101-7583
a. Define a method named_init_ to meet the following requirements:
a. Declare a class variable to store the database file and intitialize it to an empty string.
b. Define a method named set_database_name to meet the following requirements:
a. Take a database file name as a positional parameter and assign the value to the class variable.
b. If the file already exists, do nothing (we want to preserve any data in the file for continued use.)
c. If the file does not exisit, connect to the sqlite3 file and create the contacts table and the
phones table using the proper SQL CREATE TABLE statement. Use the same field names as
those used in the Entity-Relationship diagram above. Use integers for all the id's and text for all
the other data.
c. Define a method named get_database_name to meet the following requirements:
a. Return the value of the class variable that stores the database name.
d. Define a method named add_contact to meet the following requirements:
a. Take a first name and last name as positionals parameter.
b. Insert the first name and last name into the contacts table using the SQL INSERT INTO
statement.
e. Define a method named modify_contact to meet the following requirements:
a. Take a contact id, first name, and last name as positionals parameter.
b. Update the first name and last name of the cooresponding contact id in the contacts table using
the SQL UPDATE statement.
f. Define a method named add_phone to meet the following requirements:
a. Take a contact id, phone type, and phone number as positionals parameter.
b. Insert the contact id, phone type, phone number into the phones table using the SQL INSERT
INTO statement.
g. Define a method named modify_phone to meet the following requirements:
a. Take a phone id, phone type, and phone number as positionals parameter.
b. Update the phone type and phone number of the cooresponding phone id in the phones table
using the SQL UPDATE statement.
h. Define a method named get_contact_phone_list to meet the following requirements:
a. Return an array created from a query on the database using the SQL statement SELECT
contacts.*, phones.* FROM contacts LEFT JOIN phones ON
contacts. contact_id=phones. contact_id.
Transcribed Image Text:1. Write a Python program that performs as a Tuffy Titan Contacts phone list. You are given the main.py file and are required to create the Contacts class. 2. The following is the Entity-Relationship contacts contact_id first_name last_name Diagram for the data structure: Entity-Relationship Diagram Contact Anna Kendrick 1. The following is some sample data to help visualize the data model: Rebel Wilson Skylar Astin Adam DeVine phones phone_id contact_id phone_type phone_number 1. Create a Contacts class to meet the following requirements: i. Create a file named contacts.py. Sample Data Phone Numbers Home: (224)965-7800 Cell: (113)290-9210 Home: (227)673-8398 Work: (726)114-4178 Cell: (488)190-7360 Cell: (388)897-6231 Work: (675)903-1290 Cell: (747)582-9543 Home: (370)737-9472 Business: (605)101-7583 a. Define a method named_init_ to meet the following requirements: a. Declare a class variable to store the database file and intitialize it to an empty string. b. Define a method named set_database_name to meet the following requirements: a. Take a database file name as a positional parameter and assign the value to the class variable. b. If the file already exists, do nothing (we want to preserve any data in the file for continued use.) c. If the file does not exisit, connect to the sqlite3 file and create the contacts table and the phones table using the proper SQL CREATE TABLE statement. Use the same field names as those used in the Entity-Relationship diagram above. Use integers for all the id's and text for all the other data. c. Define a method named get_database_name to meet the following requirements: a. Return the value of the class variable that stores the database name. d. Define a method named add_contact to meet the following requirements: a. Take a first name and last name as positionals parameter. b. Insert the first name and last name into the contacts table using the SQL INSERT INTO statement. e. Define a method named modify_contact to meet the following requirements: a. Take a contact id, first name, and last name as positionals parameter. b. Update the first name and last name of the cooresponding contact id in the contacts table using the SQL UPDATE statement. f. Define a method named add_phone to meet the following requirements: a. Take a contact id, phone type, and phone number as positionals parameter. b. Insert the contact id, phone type, phone number into the phones table using the SQL INSERT INTO statement. g. Define a method named modify_phone to meet the following requirements: a. Take a phone id, phone type, and phone number as positionals parameter. b. Update the phone type and phone number of the cooresponding phone id in the phones table using the SQL UPDATE statement. h. Define a method named get_contact_phone_list to meet the following requirements: a. Return an array created from a query on the database using the SQL statement SELECT contacts.*, phones.* FROM contacts LEFT JOIN phones ON contacts. contact_id=phones. contact_id.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Requirement Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education