Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

kjbjYou have been given a file named employeeInfo.csv . This file contains records of the university employees. There are five columns with labels: SNo,

kjbjYou have been given a file named "employeeInfo.csv". This file contains records of the university employees. There are five columns with labels: SNo, FirstName, LastName, DepartmentName, and DateOfJoining. SNo represents the record number. FirstName and LastName represent the first and the last names of the employees respectively. DepartmentName represents the department name an employee is appointed in. DateOfJoining represents the date on which an employee was appointed in the respective department. An employee may be cross-appointed in different departments on different dates.
You need to write an EmployeeDB class that maintains the database of all university employees and departments. It must contain the following:
The class constructor will receive the filename and use it to create an instance of the class. It will also initialize an empty employee dictionary emp_dict and an empty employee object list emp_ob j_list. You will hide all three instance variables (make them private by adding the double underscore preceding the variable names).
The read_file method will read the csv file (filename was passed to the constructor). It will store the file contents in emp_dict. For each row of the csv file, cells in the first column (SNo) will be added as keys. The cells from the remaining columns will be added as values in the dictionary in the form of a list. In the end, this method will print xx records added to the dictionary., where xx is the length of the dictionary. Example:
The first record of the employeeInfo.csv file is 1, Will, Bradshaw, Biology, 2016-06-04. The read_file will save this record as emp_dict[1]=[Will,Bradshaw,Biology,2016-06-04].
There will be one accessor method: get_ob j_lst. It will return the employee object list emp_ob j_list.
The emp_exists method will receive an employee object and check if the emp_obj_list contains another employee object with identical attribute values (first name, and last name). It will return the index of the identical employee object if found, otherwise, it will return -1.
The add_emp_data method will read the employee dictionary emp_dict and add the unique employees to the employee object list emp_obj_list. Please note that for each record (value as a list) in the dictionary, the first two attribute values (first name and last name - all strings) represent an employee object. The remaining two attribute values represent a department object (department name - string, and joining date - string). This method will use the emp_exists method to check if the employee object with identical values already exists in the emp_obj_list or not. If the current record represents a unique employee not currently in the emp_obj_list, then a new employee object will be added to the emp_obj_list. In addition, you will add the department object to its respective employee object. To summarize, for each record in the dictionary:
(a) You create a new employee object (this will generate a new incremental employee id).
(b) You add the newly created employee object to the emp_obj_list if it does not exist in the list already.
(c) In case the employee object already exists in the list, the newly incremental employee id should be decremented (because we never used the newly created employee object). You use the decrementEmpID method of the Employee class to decrement the emID by 1.
(d) You create and add the department object to its respective employee object using the add_dept method of the Employee class.
(e) In the end, this method will print xx unique employees added to the database., where xx is the number of unique employees added to the emp_obj_list.
The print_cross_emp method will print the information of employees who are crossappointed in more than one department. If such records are found in the emp_ob j_list, the method will print Record XX found!, where XX is the number of such records found so far. Following this print statement, the method will print the employee object. The method will then print Appointments found: followed by the respective department objects. To print the employee objects and department objects, the method should make use of their respective __str__ methods. The printing format can be seen in the test case output.
The remove_emp method will receive an employee id and remove the employee if it exists in the emp_obj_list. If the employee is found, then it will remove the employee object and print Successfully removed employee with employee id: xx, where xx is the input employee id. Otherwise, it will print Employee not found!.
The date_diff method will receive an employee id and check if the employee is cross-appointed or not i.e., the employee is appointed in more than one department or not. If the employee is not cross-appointed, then the method will print Employee is not cross-appointed. Otherwise, the method will compute the maximum differences between the joining dates of the cross-appointments. The maximum differenc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions