Project 3 - Data Processing
Due - Wednesday, April 4, 2007
The goal of this project is to give you experience using
iteration, file i/o, classes, and lists. You will write a program
that reads from a file information about employees of an
organization and their pay rates. For each employee, your program
will create an object to store the employee's information and
insert the object into a list. Your program will then calculate
the amount each employee will receive on his/her paycheck.
The input file from which your program will read will contain one
line for each employee. Each line will have five space-delineated
fields denoting the first name, last name, title, yearly salary,
and pay frequency. The frequency denotes the number of paychecks
the employee receives in a year (e.g., 12 would mean the employee
was paid every month, 10 would mean the employee was only paid for
10 months, and 24 would mean the employee was paid twice per
month). An example would look as follows:
FirstName:Bob LastName:Smith Title:Staff Salary:45000
Frequency:12
FirstName:Ann LastName:Wang Title:Professor
Salary:80000 Frequency:10
FirstName:Alice: LastName:Banerjee Title:RA Salary:20000 Frequency:24
For each line in the file, your program will read the line, parse
it to extract the five pieces of information, and create an
Employee object. Your Employee class will have data
members to hold the first name, last name, title, salary, and
frequency respectively. You will then insert the Employee
object into a list contained in an EmployeeDB object.
Once you have inserted all employee information into your
database, you will calculate the pay for each employee as
described below and save the result to a file.
Part 1 - 75%
For part 1, implement the following:
Employee - The Employee class will have six data members: firstName, lastName, title, salary, payFrequency, and currentPayAmount. It will also have the following methods:
- __init__ - The constructor takes as input initial values for all data members except currentPayAmount and stores the data in the object appropriately. It will also initialize currentPayAmount to 0.
- print - The print method takes as input self and prints all information contained in the object.
- calculatePay - The calculatePay method takes as input self and calculates and stores a value for currentPayAmount. The currentPayAmount is calculated by dividing the salary by the payFrequency.
- getOutputData - The getOutputData method takes as input self and returns a string containing the first and last name of the employee along with his/her current pay in the following format: FirstName:Bob LastName:Smith Pay:3750.
EmployeeDB - The EmployeeDB class will have one data member: a list that will hold Employee objects. It will also have the following methods:
- __init__ - The constructor method takes as input self and a string representing a file name. It will open the file and for each line it will read the line, parse it to extract the five pieces of data it contains, create an Employee object containing the information, and invoke the addEmployee method passing in the new Employee object.
- addEmployee - The addEmployee method takes as input self and the Employee object to be added. It appends the object to the end of the list of Employee objects.
- print - The print method takes as input self and uses a loop to invoke the print method on each Employee object in the list.
- calculateCheckAmounts - The calculateCheckAmounts method takes as input self and will use a loop to invoke the calculatePay method on each Employee object.
- saveToFile - The saveToFile method takes as input self and a string representing a file name. It will open a file using the file name given. It will then use a loop to invoke the getOutputData method for every Employee object and save the result of the method in the file.
Driver - The driver will prompt the user for the name of the file
where the employee information it stored. It will then create a
new EmployeeDB object passing in the file name. Next, it will
invoke the calculateCheckAmounts method on the EmployeDB object.
Finally, it will prompt the user for the name of the file where
the calculated information should be stored and pass the input to
the saveToFile method of the EmployeeDB object.
Part 2 - 10%
For part 2, you will modify the Employee class such that it appropriately deducts taxes from the employee's pay. You will add the following method the the Employee class:
- getTaxRate - The getTaxRate method will takes as input self and will return the rate of taxation for the employee based on his/her salary. Use the following table to determine the rate of taxation:
Yearly Salary | Tax Rate |
$0-$7500 | 10% |
$7501-$25000 | 15% |
$25001-$75000 | 20% |
$75001-$150000 | 25% |
$150001- | 30% |
You will also modify the calculatePay method such that it first invokes getTaxRate to determine the appropriate rate of taxation and then deducts the appropriate amount from the pay.
Part 3 - 15%
For part 3, you will enable the user to give bonuses to specific
employees. In your driver, you will implement a loop between the
portion of the program that invokes the calculateCheckAmounts
method and the portion that saves the results to a file. The loop
will enable the user to give bonuses to several employees. It
will prompt the user for the name (first and last) of the employee
to which it wishes to give the bonus and the amount of the bonus.
It will then invoke a findAndGiveBonus method on the EmployeeDB
object, passing in the first name, last name, and bonus amount.
The findAndGiveBonus method of the EmployeeDB will search the list
of Employee objects until it finds the object containing the
specified first and last name. You may want to implement one or
more methods to compare the specified first and last name to the
first and last name contained in an Employee object. Once it the
findAndGiveBonus method has found the correct Employee, it will
invoke a method that will increase the pay by the bonus amount.
Be sure to handle the situation in which the specified Employee is
not found.
Implementation Requirements and Hints
- Make sure to implement and test your program in small
increments. For example, you can begin by implementing the Employee class. Then, implement the EmployeeDB class one method at a time.
- You should refer to the python library reference (http://docs.python.org/lib/string-methods.html)
for information about parsing strings. In particular, you will
probably need the split method.
- You do not need to submit each part separately. If you complete parts 2 and/or 3, you can submit one working program that supports the functionality for the part you have completed.
Due 1:30PM, Wednesday, April 4, 2007
- Complete and submit your working code. Turn in a hard copy in class and place a copy of your .py files in /home/submit/cs110-s07/username.
- Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
- Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other
source including another text book, a web page, or another
student (current or former). You must provide citations for any
sources you have used in designing and implementing your program.
Sami Rollins