Project: Employee directory

Write a class called Employee with private data members for an employee's name, ID number, salary and email address. It has an __init__ method that sets them and a getter for each one.

Then write a separate function, outside the class, called make_employee_dict. It takes four lists as parameters: names, ID numbers, salaries and email addresses. All four are the same length. The function goes through the lists, creates an Employee for each position, and adds it to a dictionary. The dictionary's keys are the ID numbers and its values are the Employee objects. The function returns the dictionary.

Here is how it could be used:

emp_names = ["Tuan", "Rachel", "Brandon"]
emp_ids = ["1000", "1001", "1002"]
emp_sals = [30, 35, 28]
emp_emails = ["Tuan@aol.com", "Rachel@aol.com", "Brandon@aol.com"]
result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails)
print(result["1000"].get_name())

When you test, remember that printing an object of your own class shows only its type and a memory address. To see its values, call its getters, as the last line above does.

Save the file as make_employee_dict.py.

Show a solution

Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail.

Projects run on your own computer, so you tell us when you are done.