Lab 13: Payroll Processing
Objectives
- Use the
Scanner
class to read text files into memory - Use the
PrintWriter
class to write text to files - Handling exceptions in an appropriate manner
- Use the
java.util.ArrayList
collection class to hold class data
Resources
- Accept the GitHub Classroom assignment invitation in Canvas and then, in IntelliJ, create a new project from Version Control using the repository URL.
Introduction
In this assigment you will implement a basic payroll program that reads and writes in various file formats.
PayrollGenerator
This is your program's primary driver. It will ask the user for the filename of the XML file that holds the information for the business' staff members. It will then ask for the timesheet directory and the period's start date.
The driver will take the information from the XML file and generate a list of employees. For the hourly employee, it will calculate the number of hours worked during the pay period using the corresponding CSV timesheet file. The pay period is 15 days. It will then print the paystub information for each employee, which includes the employee information, a list of deductions sorted from largest to smallest, and a breakdown of their pay.
The output for each paystub must match this format:
Pay Period Start:1895-01-01
Employee ID: 1
Name: Stephen Grover Cleveland
Address: 1600 Pennsylvania Avenue NW, Washington, DC 20500
Type: FullTime
Salary: 50000.00
Deductions:
Civil War Sub 300.00
Blind Teachers Fund 50.00
Total 350.00
Payment Details:
Salary: 50000.00
Gross Pay: 2083.33
Net Pay: 1733.33
To implement this program, you have been provided with
JavaDoc that detail the
classes representing employees and deductions, a utility
class for parsing employee information from the XML file,
and helper methods for PayrollGenerator
.
XML Staff File
The XML file will consist of single-line and multi-line elements.
Single line elements, also called inline elements, are of the form
<type>value</type>
and take up a single line. <type>
and </type>
are called opening and closing tags, and the value can represent numeric
or text data. Multi-line elements, also called nested elements, consist
of multiple lines where the first line contains <type>
and the last
line contains </type>
. Between the opening and closing tags of nested
elements can be multiple inline and nested elements. You can assume
the XML structure is correct and follows the line structure described here.
Therefore, your code can assume each opening tag has a closing tag,
inline elements take up a single line that consists of a tag separated
by a value, and nested elements contain a mixture of inline and nested
elements.
Here is a sample portion of an XML file:
<employee>
<id>1</id>
<name>Turanga Leela</name>
<age>25</age>
<address>1081 Proximal St., New New York, Earth</address>
<email>leela@planetexpress.com</email>
<type>fulltime</type>
<salary>50000</salary>
<title>Ship Captain</title>
<deduction>
<type>Pet Sitter</type>
<amount>200.50</amount>
</deduction>
<deduction>
<type>Alien Orphan Fund</type>
<amount>100</amount>
</deduction>
</employee>
The staff XML file will contain nested elements for employees, volunteers, and other types of staff. You will need to parse only the employee elements given the above mentioned structure. If there is an error when parsing the information for an employee, for example, an incorrect data type, skip parsing that employee and move on to the next. You are not allowed to use Java XML parser libraries. If the provided staff filename is not an XML file or there is an error opening it, the program should terminate and print a descriptive error message to the console.
CSV Timesheets
A CSV (comma-separated-value) file contains multiple lines separated by commas and can represent data in a 2D matrix. Each line can be seen as a row, and the commas mark the separation between the columns. Each line can contain multiple pieces of information, such as the date, time in, and time out of a work shift. The first line of a CSV includes the column names. There is no guarantee that the number of elements on each line is the same as the number of columns.
Here is a sample portion of a CSV file:
date,time-in,time-out
2024-01-04,07:30,15:00
2024-01-11,07:30,15:00
2024-01-18,08:00,16:00
You can assume that all the available CSV files are in one directory. Each file details the dates and hours worked over 2 months for an employee. Not every date will have an entry in the CSV file. If an error occurs when reading a line of the CSV, skip the line and continue reading the rest of the CSV file. If there is an error opening the timesheet CSV file for an employee, stop reading the file and do not update the hours for that employee.
Repository Structure
The data files are located in the project repository and should not
be moved. The XML file, staff.xml
, is located in the project's root
directory and several time sheet CSV files are located in the timesheets
directory.
Addendum
Writing Pay Stubs
Update your PayrollGenerator
program to generate paystubs for each
employee. Each paystub must be written to a separate file with an
appropriate filename. All of the files must be written to a directory
called payStubs
found in the root directory for the project. These
files should be committed with your completed solution. If the payStubs
directory does not exist when your program is run, the program should
create the folder.
In addition, you should modify your code so that whenever an exception is encountered that causes you to skip over data from a data file, log an error message indicating the nature of the error to a log file.
You may find this logging Taylorial helpful.
Acknowledgment
This laboratory assignment was developed by Dr. Roby Velez.