Question

Please do not copy from other response this is the second time to post this question...

Please do not copy from other response this is the second time to post this question

I need a python 3 help.

from question 1.2,

r.add_student(Student("White", "Kate", 78787878, "whitek@rt.edu"))

>>> r.lookup("White")

White, Ann -- Phone: 35435

Email Address: whitea@rt.edu

White, Kate -- Phone: 78787878

Email Address: whitek@rt.edu

this part got me so stressed. I don't know how to return two students whose names are the same white.

Part 1. Classes

Question 1.1

Define a Student class that follows the doctests below:

class Student:

  """

>>> st1 = Student("Black", "John", 12345, "blackj@uscd.edu")

>>> print(st1)

Black, John -- Phone: 12345

Email Address: blackj@uscd.edu

>>> st2 = Student("White", "Ann", 35435, "whitea@rt.edu")

>>> print(st2)

White, Ann -- Phone: 35435

Email Address: whitea@rt.edu

"""


Question 1.2

Now you can use your Student class to create an rolodex for storing contacts of your friends. Your class should allow to add new students to rolodex,

search it for a friend, and view their contact information.


You need to develop a Rolodex class, its behaviur should follow the doctests below. Hint: Python's built-in dictionaries might be useful.

class Rolodex:

  """

>>> r = Rolodex()

>>> r.add_student(Student("Black", "John", 12345, "blackj@uscd.edu"))

>>> r.add_student(Student("White", "Ann", 35435, "whitea@rt.edu"))

>>> r.lookup("Black")

Black, John -- Phone: 12345

Email Address: blackj@uscd.edu

>>> r.lookup("White")

White, Ann -- Phone: 35435

Email Address: whitea@rt.edu

>>> r.add_student(Student("White", "Kate", 78787878, "whitek@rt.edu"))

>>> r.lookup("White")

White, Ann -- Phone: 35435

Email Address: whitea@rt.edu

White, Kate -- Phone: 78787878

Email Address: whitek@rt.edu

"""

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

Solution:

Please find below the code :

students = []

class Student:
def __init__(self, last_name, first_name, phNumber, email):
self.last_name = last_name
self.first_name = first_name
self.phNumber = phNumber
self.email = email

def getLastname(self):
return self.last_name
  
def getFirstname(self):
return self.first_name

def getPhNumber(self):
return self.phNumber

def getEmail(self):
return self.email

def setFirstname(self, first_name):
self.first_name = first

def setLastname(self, last_name):
self.last_name = last

def setPhNumber(self, phNumber):
self.phNumber = phNumber

def setEmail(self, email):
self.email = email

def __str__(self):
return self.last_name + ", " + self.first_name + " -- Phone: " + str(self.phNumber) + '\n' + "Email Address: " + self.email + '\n'

class Rolodex:
def add_student(self, st):
global students
students.append(st)
  
def lookup(self, name):
for student in students:
if(student.getLastname() == name):
print(student)

st1 = Student("Black", "John", 12345, "blackj@uscd.edu")
print(st1)
st2 = Student("White", "Ann", 35435, "whitea@rt.edu")
print(st2)
r = Rolodex()
r.add_student(Student("White", "Ann", 35435, "whitea@rt.edu"))
r.add_student(Student("Black", "John", 12345, "blackj@uscd.edu"))
r.lookup("Black")
r.lookup("White")

Output:

Add a comment
Know the answer?
Add Answer to:
Please do not copy from other response this is the second time to post this question...
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
  • (Please do not copy and paste from another question. I am new to this and need...

    (Please do not copy and paste from another question. I am new to this and need it to be simple) Draw an ERD for a “Hospital” with many departments and employees in each department. show things like (one to one, one to many, many to many). What attributes would you store regarding each objects/class/data entities? Thank you! (Example) FIGURE 4-10 An ERD for a bank with many branches Customer cust number-PK name bill address home phone office phone = Account...

  • I ONLY need question 2 part C AND D answered...it is in bold. Please do not...

    I ONLY need question 2 part C AND D answered...it is in bold. Please do not use hash sets or tables. In java, please implement the classes below. Each one needs to be created. Each class must be in separate file. The expected output is also in bold. I have also attached the driver for part 4 to help. 1. The Student class should be in the assignment package. a. There should be class variable for first and last names....

  • the first question java code eclipse app the second question is java fx gui caculator please...

    the first question java code eclipse app the second question is java fx gui caculator please fast 1. Create project called "YourFirstName_QUID'. Eg. Aliomar_202002345 2. Create two package Q1 and Q2. 3. Add your name and studentID as comments on the top of each Java source file you submit. Question 1. Bookings APP [80 Points-six parts] Implement the following hotel booking system. Use the following class diagram to understand the structure of the system's classes, their attributes operations (or methods),...

  • HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

    HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...

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