Week 14 Lab: Payroll Processing

Objectives

Resources

Introduction

In this assignment you will implement a basic payroll program that reads and writes in various file formats.

PayrollGenerator

This is your program's primary driver. It must perform the following operations distributed among main() and the helper methods described in the JavaDoc. You can assume that all files and directories are within a data folder that is in the project's root directory. See Repository Structure for more information on the provided files and their locations.

The output for each paystub must match this format:

Pay Period Start:1895-01-01
Employee Information:
        ID:                               1
	Name:              Grover Cleveland
	Address:          1600 Pennsylvania
	Type:                      Fulltime
	Salary:                    50000.00
Deductions:
	Civil War Sub:               300.00
	Blind Teachers:               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.</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</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 in a directory calleddata which is located in the project's root directory. These files should not be moved. Within the data folder is the XML file, staff.xml, and the timesheets directory which stores the time sheet CSV files. The paystubs directory will also live in the data directory.

Sample Output

The following shows a sample output given the provided files. This program should also add three files paystub1.txt, paystub2.txt2, and paystub4.txt to the data/paystubs folder.

Welcome to Payroll Manager 3000
Enter the employee list as an .xml file.
data/staff.xml
Error with Employee arguments: Invalid arguments for Employee: Id(3),Name(Hermes Conrad),Address(null),Deductions([solution.Deduction@5010be6])
Error employee 2 already in list. Skipping. 
Error parsing Employee data: For input string: "Thirty-five Dollars"
Enter the timesheet directory.
data/timesheets
Enter the start of the pay period in the form of yyyy-mm-dd: 
2024-01-01
Error parsing date or time
Text '07:3015:00' could not be parsed, unparsed text found at index 5
Error parsing date or time
Text '204-02-08' could not be parsed at index 0
Enter the paystub directory: 
data/paystubs
Entered directory does not exist. Creating it

Writing to data/paystubs/paystub1.txt
Pay Period Start:2024-01-01
Employee Information
	ID:                               1
	Name:                 Turanga Leela
	Address:          1081 Proximal St.
	Type:                      Fulltime
	Salary:                    50000.00
Deductions:
	Pet Sitter:                  200.50
	Alien Orphan:                100.00
	Total:                       300.50
Payment Details:
	Salary:                    50000.00
	Gross Pay:                  2083.33
	Net Pay:                    1782.83


Writing to data/paystubs/paystub2.txt
Pay Period Start:2024-01-01
Employee Information
	ID:                               2
	Name:                 Philip J. Fry
	Address:              1 Slacker Way
	Type:                        Hourly
	Rate:                         25.00
Payment Details:
	Hours:                        24.00
	Rate:                         25.00
	Gross Pay:                   600.00
	Net Pay:                     600.00


Writing to data/paystubs/paystub4.txt
Pay Period Start:2024-01-01
Employee Information
	ID:                               4
	Name:              Bender Rodríguez
	Address:            12 Bending Ave.
	Type:                        Hourly
	Rate:                         30.00
Deductions:
	Loan Shark:                  300.00
	Bending Union:               100.75
	Cigar Tax:                    50.25
	Total:                       451.00
Payment Details:
	Hours:                        23.00
	Rate:                         30.00
	Gross Pay:                   690.00
	Net Pay:                     239.00

Acknowledgment

This laboratory assignment was developed by Dr. Adela Velez.

See your professor's instructions for details on submission guidelines and due dates.