Question

A cell phone has the ability to save contact information. In this assignment, you will simulate...

  • A cell phone has the ability to save contact information. In this assignment, you will simulate the contact list for a very simple cell phone.
  • Download lab8.py below, rename it according to the instructions above, and make sure you understand it.
  • Take the program above and modify it by adding the missing Contact class such that when the program is run, it produces this output.
  • Hint: for help on formatting output, revisit the online textbook's chapter 9.5.1

Grading - 10 points

  • 2 points - The constructor of the Contact class is correct.
  • 2 points - The reader methods of the Contact class are correct.
  • 2 points - The writer methods of the Contact class are correct.
  • 2 points - The print_entry method of the Contact class is correct.
  • 2 points - Your program's output matches the output format of the transcript above (1 point for each type of difference up to 2 points).

This is the provided lab8.py:

# -----------------------------------------------------
# CSCI 127, Lab 8
# March 12, 2020
# Your Name
# -----------------------------------------------------

# Your solution goes here...

  
# -----------------------------------------------------
# Do not change anything below this line
# -----------------------------------------------------

def print_directory(contacts):
print("MSU Contacts:")
print("----------------------------------------")
for person in contacts:
person.print_entry()
print("----------------------------------------\n")

# -----------------------------------------------------

def main():
  
prof_892 = MSUContact("first1", "last1", "###-###-####")
mascot = MSUContact("first2", "last2", "###-###-####")
director_CS = MSUContact("first3", "last3", "###-###-####")
president = MSUContact("first4", "last4", "###-###-####")
  
contacts = [prof_892, mascot, director_CS, president]
print_directory(contacts)

mascot.set_first_name("Champ")
  
prof_892.set_title("Instuctor")
director_CS.set_title("Director")
president.set_title("President")

print_directory(contacts)
  
contact = prof_892
print(contact.get_first_name() + "'s MSU phone line is", \
contact.get_line_number())

# -----------------------------------------------------

main()

This is the provided output, with numbers altered, but formatted the same:

MSU Contacts:
----------------------------------------
first1 last1                ###-###-####
first2 last2                ###-###-####
first3 last3                ###-###-####
first4 last4                ###-###-####
----------------------------------------

MSU Contacts:
----------------------------------------
Instuctor first1 last1      ###-###-####
Champ Bobcat                ###-###-####
Director first3 last3       ###-###-####
President first4 last4      ###-###-####
----------------------------------------

first1's MSU phone line is ####

In censorship of names and numbers, I hope the intent of the code was not lost. I need to create a class of some sort to create the intended output.

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

As per given question description, here is the required source code for solution in text and image format:

Text:

class MSUContact:
def __init__(self,fname,lname,number):
self.fname = fname
self.lname = lname
self.number = number
self.title = None

def set_first_name(self,fname):
self.fname=fname
  
def set_title(self,title):
self.title = title
  
def print_entry(self):
if self.title==None:
print(self.fname+" "+self.lname+"\t"+self.number)
else:
print(self.title+" "+self.fname+" "+self.lname+"\t"+self.number)
  
def get_first_name(self):
return self.fname

def get_line_number(self):
return self.number
  
def print_directory(contacts):
print("MSU Contacts:")
print("----------------------------------------")
for person in contacts:
person.print_entry()
print("----------------------------------------\n")

def main():
prof_892 = MSUContact("first1", "last1", "###-###-####")
mascot = MSUContact("first2", "last2", "###-###-####")
director_CS = MSUContact("first3", "last3", "###-###-####")
president = MSUContact("first4", "last4", "###-###-####")
  
contacts = [prof_892, mascot, director_CS, president]
print_directory(contacts)
  
mascot.set_first_name("Champ")
  
prof_892.set_title("Instuctor")
director_CS.set_title("Director")
president.set_title("President")
  
print_directory(contacts)
  
contact = prof_892
print(contact.get_first_name() + "'s MSU phone line is", \
contact.get_line_number())

main()
  
Image:

Sample Output:

Add a comment
Know the answer?
Add Answer to:
A cell phone has the ability to save contact information. In this assignment, you will simulate...
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
  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone...

    This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone book using a linked list to keep people's names and phone numbers organized in alphabetical order. 1. Define a structure to hold the contact information including: name, phone number, a pointer to the next node in the list. Example: struct ContactNode { string name; string phoneNumber; ContactNode *next; } 2. Define a class containing the structure and the appropriate methods to update and retrieve...

  • C++ In this assignment, you will write a class that implements a contact book entry. For...

    C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

  • PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a...

    PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...

  • My CSC 220 teacher has given this as a homework assignment and starting it has not...

    My CSC 220 teacher has given this as a homework assignment and starting it has not made much sense and am generally lost on this assignment help would be much appreciated. I put everything from the assignment power point slides she gave us in here so the expert has everything im working with as well. Dequeue Please implement your own Dequeue class which has following methods boolean add(E e)= void addLast(E e) void addFirst(E e) E getFirst( ) = E...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read Mo...

    Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read MotoGP rider information from an input file. You will need a MotoGpRider class whose instances will be used to store the statistics for a MotoGP motorcycle racer. The Rider class will have attributes for last name, first name, racing number, nation, motorcycle make, world championship points, world championship position, and an array that stores the number of top finishes (number...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

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