Create a program that will read in a file of employee details and load an array of employee objects. Then print a menu that will allow the user to search and print from the that array of employees.

You will be given an input file that consists of employee name, employee number, department number, and title. It will look like this:

You will create a class Employee that represents one employee. That class will have the following private variables:

  • __firstName (string)
  • __lastName (string)
  • __employeeID (int)
  • __department (int)
  • __title (string)

To create the Employee object you must initialize it with all five private variables according to the type above. The initialize method will be like this: def __init__(self, fname, lname, eid, dept, title)

Requirements:

  • In main you will do the following in order:
    • Read the input file and create an array of Employee objects. Use the readFile() function as described below.
    • Display a menu which looks exactly like this:
MAIN MENU
=======================================
1: List all Employees
2: List all Employees by Department
3: Find Employee by Name
4: Find Employee by ID
Anything else to quit
Choose an option:
  • The user can enter 1-4 and the functions listed will execute and then re-display the menu. If the user enters anything else but 1-4, the program will quit.
  • The following class Methods you must implement (you can implement more, but you have to implement at least these)
    • def __init__(self, fname, lname, eid, dept, title): this method will initialize your object from the variables passed in. You must do proper error checking and conversion so that each private variable is initialized properly.
    • def printObject(self): this method will print all the private variables in the object on one line like this: Peppermint, Patty, 23012, 443, vice president of finance
    • def getDepartment(self): returns the value of __department (integer)
    • def getEmployeeID(self): returns the value of __employeeID (integer)
    • def getFirstName(self): returns the value of __firstName (string)
    • def getLastName(self): returns the value of __lastName (string)
  • The following Functions you must implement (you can implement more, but you have to implement at least these):
    • def readFile(employees): accepts an empty List (called employees), opens the file for reading, loads all the employees from the file into a List of employee objects. Note you do not need to return the List because you pass it in to start with, and it is passed by reference, so it does not need to be returned.
    • def mainMenu(): this will print the main menu as shown in the examples, and will ask the user for a choice, and return ONLY one number from 0-4. Return 1-4 if the user enters 1, 2, 3, or 4, and return 0 in all other cases.
    • def listAll(employees): pass it your full List of Employee objects and print all the employees as shown in the examples. Use the printObject() method to do this.
    • def listAllByDept(employees): pass it your full List of Employee objects and print all the employees as shown in the examples sorted by department . DO NOT re-order your original List. This function should not modify your List of employees, but should only sort the List into a temporary List that can be printed.
    • To accomplish this you can use the sorted() function like this: tempEmployees= sorted(employees, key=lambda x: x.getDepartment())
    • That code will sort the List of employees by department, and put the sorted List into a new List called tempEmployees. Then you can print that sorted List.
    • Use the printObject() method to print your temporary List.
    • def getByName(employees, name): Pass in the employees List, and the name to search. Return ALL the employees (i.e. return a List of Employees) that have a name match in the first or second name. If nothing is found, return an empty List. This should be case insensitive. See the examples.
    • def getByID(employees, eid): Pass in the employees List, and the employee id to search. Return a single Employee object if found, return 0 otherwise.
  • All normal rules of good programming practice and modularity apply.

Here is the input needed for the assignment:

Charlie Brown,54301,345,director of construction
Wood Stock,43199,726,marketing manager
Lucy Van-Pelt,83023,566,customer service manager
Sally Brown,99123,566,customer service representative
Peppermint Patty,23012,443,vice president of finance
Snoopy Brown,22834,101,chief executive officer
Stock Character, 43011, 101, chief technology officer
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.