Answered step by step
Verified Expert Solution
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 crossappointed 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 empdict and an empty employee object list empob jlist. You will hide all three instance variables make them private by adding the double underscore preceding the variable names
The readfile method will read the csv file filename was passed to the constructor It will store the file contents in empdict. 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 Will, Bradshaw, Biology, The readfile will save this record as empdictWillBradshawBiology
There will be one accessor method: getob jlst It will return the employee object list empob jlist.
The empexists method will receive an employee object and check if the empobjlist 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
The addempdata method will read the employee dictionary empdict and add the unique employees to the employee object list empobjlist. 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 empexists method to check if the employee object with identical values already exists in the empobjlist or not. If the current record represents a unique employee not currently in the empobjlist, then a new employee object will be added to the empobjlist. 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 empobjlist 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
d You create and add the department object to its respective employee object using the adddept 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 empobjlist.
The printcrossemp method will print the information of employees who are crossappointed in more than one department. If such records are found in the empob jlist, 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 removeemp method will receive an employee id and remove the employee if it exists in the empobjlist. 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 datediff method will receive an employee id and check if the employee is crossappointed or not ie the employee is appointed in more than one department or not. If the employee is not crossappointed, then the method will print Employee is not crossappointed Otherwise, the method will compute the maximum differences between the joining dates of the crossappointments. The maximum differenc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started