Question

Part 1 (employee.py): Write a class name Employee that holds the following data about an employee...

Part 1 (employee.py): Write a class name Employee that holds the following data about an employee in attributes:name, ID number, department and job title. Once you have written the class, write a program that creates three Employee objects to hold the following data: The program should store this data in the three objects, then display the data for each employee on the screen as a table like this (Use fstring or "format" function to format the output as a table, like you did in the Assignment#3).

Part 2 (ems.py): Create the EmployeeManagementSystem (ems) class which stores Employee objects in a dictionary. Use the employee ID number as the key and the Employee object as the value. The program should present a menu that lets the user to perform the following actions: Look up an employee in the dictionary Add a new employee to the dictionary Change an existing employee's name, department and job title in the dictionary. Delete an employee from the dictionary Output all employees' information in table (as shown below. Use fstring or "format" function to format the output as a table, like you did in the Assignment#3).) Quit the program When the program ends, it should pickle the dictionary and save it to a file. Each time program starts, it should try to load the pickled dictionary from the file. If the pickled dictionary file does not exist, the program should start with an empty dictionary, create the 3 objects shown in the table below and add them to the empty dictionary.

Name ID Number Department Job Title

Susan Meyers 47899 Accounting Vice President

Mark Jones 39119 IT Programmer

Joy Rogers 81774 Manufacturing Engineer

Sample output

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 1

Enter an employee ID number: 47899

Susan Meyers 47899 Accounting Vice President

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 1

Enter an employee ID number: 234

The specified ID number was not found

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 2

Enter employee name: Jane

Enter employee ID number: 23456

Enter employee department: IT

Enter employee title: Tester

The new employee has been added.

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 3

Enter employee ID number: 234

The specified ID number was not found.

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 3

Enter employee ID number: 23456

Enter the new name: Jane Wayne

Enter the new department: IT

Enter the new title: Tester

Employee information updated.

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 4

Enter employee ID number: 23456

Employee information deleted.

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 5

Name ID Number Department Job Title

------------------------------------------------------------

Susan Meyers 47899 Accounting Vice President

Mark Jones 39119 IT Programmer

Joy Rogers 81774 Manufacturing Engineer

Menu

----------------------------------------

1. Look up an employee

2. Add a new employee

3. Change an existing employee

4. Delete an employee

5. Output all employees' information on a table

6. Quit the program

Enter your choice: 6

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

'''
Python version : 2.7
Python file : employee.py
Python program to create Employee class
'''
class Employee:
  
   # constructor to initialize the fields of the Employee
   def __init__(self, id, name, department, job_title):
      
       self.id = id
       self.name = name
       self.department = department
       self.job_title = job_title
      
   # return string representation of the Employee  
   def __str__(self):
       return "{0} {1} {2} {3}".format(self.name,self.id,self.department,self.job_title)
      
   # update the department of the Employee  
   def set_department(self, department):
       self.department = department
      
   # update the name of the Employee  
   def set_name(self, name):
       self.name = name
  
   # update the job title of the Employee
   def set_job_title(self, title):
       self.job_title = title
              
#end of employee.py  

Code Screenshot:

'''
Python version : 2.7
Python file : ems.py
Python program to create and test EmployeeManagementSystem class
'''
import pickle
from employee import Employee

class EmployeeManagementSystem :
          
   # constructor to initialize the employee dictionary by loading the data from file, if it exists
   # else create an empty dictionary  
   def __init__(self):
      
       try:
           fp = open("empPickle","rb") # open the file in binary mode
           self.emp = pickle.load(fp) # load the data into the dictionary
           fp.close() # close the file
       except IOError: # File doesn't exist
           self.emp = {} # create an empty dictionary
          
   # function to search for an employee      
   def search_employee(self):
       id = raw_input("Enter an employee ID number: ")
       if id in self.emp.keys():
           print(self.emp[id])
       else:
           print("The specified ID number was not found")
          
   # function to add an employee to the dictionary      
   def add_employee(self):
      
       name = raw_input("Enter employee name: ")
       id = raw_input("Enter employee ID number: ")
       department = raw_input("Enter employee department: ")
       title = raw_input("Enter employee title: ")
      
       if id in self.emp.keys():
           print("The specified ID number already exists. Please try to edit the employee")
       else:
           self.emp[id] = Employee(id,name,department,title)
           print("The new employee has been added.")
          
   # function to update the name, department, title of the Employee      
   def change_employee(self):
       id = raw_input("Enter employee ID number: ")
       if id not in self.emp.keys():
           print("The specified ID number was not found. ")
       else:
           name = raw_input("Enter the new name: ")
           department = raw_input("Enter the new department: ")
           title = raw_input("Enter the new title: ")
           self.emp[id].set_name(name)
           self.emp[id].set_department(department)
           self.emp[id].set_job_title(title)

           print("Employee information updated.")

   # function to delete an employee      
   def delete_employee(self):
       id = raw_input("Enter employee ID number: ")
      
       if id in self.emp.keys():
           del self.emp[id]
           print("Employee information deleted.")
       else:
           print("The specified ID number was not found")
          
   # function to display all the employees      
   def display_employees(self):
       print("{0} {1} {2} {3}".format("Name","ID Number","Department","Job Title"))
       print("-"*70)
      
       for id in self.emp.keys():
           print(self.emp[id])
          
   # function to display the meu and perform the actions based on the choice selected
   def menu(self):
       # loop that continues till the user exits
       while True:
           print("Menu")
           print("-"*50)
           print("1. Look up an employee")
           print("2. Add a new employee")
           print("3. Change an existing employee")
           print("4. Delete an employee")
           print("5. Output all employees' information on a table")
           print("6. Quit the program")
          
           choice = int(raw_input("Enter your choice: "))
          
           if choice == 1:
               self.search_employee()
           elif choice == 2:
               self.add_employee()
           elif choice == 3:
               self.change_employee()
           elif choice == 4:
               self.delete_employee()
           elif choice == 5:
               self.display_employees()
           elif choice == 6:
               fp = open("empPickle","wb")
              
               pickle.dump(self.emp,fp)
               fp.close()
              
               break
           else:
               print("Invalid choice")

# call the menu function to EmployeeManagementSystem              
def main():
   EmployeeManagementSystem().menu()

#call the main function  
main()  
              
#end of ems.py              

Code Screenshot:

Output:

Sample run 1:

Sample run 2:

Add a comment
Know the answer?
Add Answer to:
Part 1 (employee.py): Write a class name Employee that holds the following data about an employee...
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
  • 1. Write a class named Employee that holds the following data about an employee in attributes:...

    1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present a menu that lets the user perform the following actions: ✓ Look up an employee in the dictionary ✔ Add a new...

  • Write a class named Employee that holds the following data about an employee in attributes: name,...

    Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Don't include a constructor or any other methods. Written in Python and formatted like it says below!!!!! Once you have written the class, write a program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineering...

  • please make sure to write down all the coding and the output for it and to...

    please make sure to write down all the coding and the output for it and to do all three steps Student Name: 1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Create a C# Console program. Add a class named Employee that has the following public fields:...

    Create a C# Console program. Add a class named Employee that has the following public fields: • Name. The name field references a String object that holds the employee’s name. • IDNumber. The IDNumber is an int that holds the employee’s ID number. • Department. The department field is a String that holds the name of the department where the employee works. • Position. The position field is a String that holds the employee’s job title. Once you have written...

  • Design and write a class named Employee that inherits the Person class from the previous exercise...

    Design and write a class named Employee that inherits the Person class from the previous exercise and holds the following additional data: ID number, department and job title. Once you have completed the Employee class, write a Python program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Phone Susan Meyers 47899 Accounting Vice President 212-555-1212 Mark Jones 39119 IT Programmer 212-555-2468 Joy Rogers 81774 Operations Engineer 212-555-9753 The Python program should store...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Part 1 Start by designing the Employee class Employee holds the following private attributes: a count...

    Part 1 Start by designing the Employee class Employee holds the following private attributes: a count of employees (a static variable called NUM_EMP)* an employee’s last name an employee’s first name an employeeNumber (a String that is unique – that will use the NUM_EMP)* a department a jobTitle an annual salary (e.g., 45000). NOTE: *NUM_EMP should start off as zero and get updated every time a new Employee is created. The employeeNumber always starts with empl_ followed by the current...

  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

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