Employee Payroll Project in Java

In this project you will be writing a payroll system for the Crunchy Crème Cupcake Factory.  Employees are paid twice a month, on the 15th and last day of the month.  The factory employees 3 categories of employees:

• Salaried employees who are paid based on a yearly salary, which is divided between 24 pay periods.

• Commission based employees, who have a yearly salary (24 pay periods), but also earn commission based on their sales during each pay period. 

• Hourly employees who are paid by the hour.  These employees may be eligible for overtime pay, but in general work at least 40 hours per week.

 

Your payroll system, will read a file of employee data, and store the information for each employee into an array.  Finally, you will calculate the pay for each employee by visiting each employee element in your array and calling the appropriate method to calculate pay, and print a report that has one line for each employee in the array

 

For this project you will create classes representing the different category of employees, along with an abstract employee class that contains information common to all employees (some of which is provided for you).  You will need to write the following classes:

Employee:  you will define an ABSTRACT class called employee that will serve as the base class of the other classes in your application. This class will have the following private data members:   This class MUST be named Employee

 

ID:  integer

First name:  String

Last Name:  String

Title: String

Total Pay:  Float

 

Methods:

• You will need a single constructor that receives a value for each of the data members except total pay, which should be initialized appropriately.

• You will need getter/setter methods for each data member

• This class must implement the comparable interface, which means you must write a compareTo method which will first compare the employee type (using the “instanceOf” method, and then if the type of two objects is the same, then compare the employee id.  Employees are sorted by type, and then ID

• You will also declare two abstract methods:

• One is a void method called calculatePay which given the data in the object calculates the employee’s pay, and stores it in the total pay data member.  

• The second is a void method called print().  This method will print the contents of an employee object, in the format needed by your payroll report for that type of employee.

 

Commission Employees:     This class MUST be named Commission

This class represents employees who earn commission on sales each pay period and is a subclass of class Employee.  This class has the following data members

 

Salary:  Float  //  base salary

Commission Rate: Float  // percentage of sales, earned as commission

Commission Sales:  Float   // sales this pay period

Threshold:  Float    // This is the amount of sales an employee must earn before

// they are eligible to earn commission, for example an employee

// might have to sell $15000 in products before earning 

// commission. if they sell less than $15000 they earn no 

//commission if they sell $20000 then they earn commission on

// $5000

 

Methods:

• You will need a single constructor, which receives an employees first and last name, title, type, ID, salary threshold amount, and commission rate

• You will need getters/setters for all of the private data members of this class.

• You will need a calculatePay() method, that calculates this employees pay as:

• if the employee’s sales are less than or equal to the threshold, then they earn No commission and are just give their base salary

• IF the sales are > than the threshold then the employee receives their regular salary PLUS  (the commission sales – threshold) * commission rate

 

• You will need to write a void print() method that will display the contents of this type of object in a format compatible with your payroll report.

 

 

Salaried:   this class MUST be named    Salaried

This represents a category of employees who are paid based on an annual salary, this class implements the data member:

 

Salary:  float  // annual salary 

 

Methods:

 

• You will need a single constructor, which receives an employees first and last name, title, type, ID, and salary

• You will need getters/setters for of the private data member of this class.

• You will need a calculatePay() method, that calculates this employees pay as:

 

   totalPay = (Salary/24);

 

• You will need to write a void print() method that will display the contents of this type of object in a format compatible with your payroll report.

 

Hourly:  This class MUST be named Hourly

This represents a category of employees who are paid by the hour.  These employees may or may not be eligible for overtime pay if they work more than 80 hours during the pay period.  This class implements the data members:

 

Hours Worked:  Float   // hours worked this pay period

Hourly Rate:   Float

Overtime Eligible:  Boolean

 

Methods:

 

• You will need a single constructor, which receives an employees first and last name, title, type, ID, hourly rate, and overtime eligible. 

• You will need getters for all of the private data members of this class.

• You will need a SINGLE setter for the Hours Worked data member.

• You will need a calculatePay() method, that calculates this employees pay as:

• If the employee is NOT overtime eligible the pay is calculated as the hours worked times the hourly rate.

• If the employee IS overtime eligible for the first 80 hours they are paid by their hourly rate, for every hour over 80, they are paid 1 ½ times their hourly rate

 

• You will need to write a void print() method that will display the contents of this type of object in a format compatible with your payroll report.

 

Your main program:

 

Again your main program/ and supporting static methods are the workhorses of this project, USE FUNCTIONAL DECOMPOSITION… It is not acceptable for main to do all of the work.

 

1. We are going to use Polymorphism to allow us to store objects of our various employee types into an array of the abstract type Employee.  We will begin by declaring an array of type employee. This will contain the information read from the main data file for each employee. WE employee 30 employees.

TASKS

2. You will prompt the user for the name of and open the employee data file, and read each line, since there are 3 different kinds of employees, there are 3 different line formats one for each category of employee, these are:

 

C  1234  Sam  Jones  Salesman  45000.00  10.00  7000.00 8500.00

S  2312  Larry Smith  Manager  54000.00

H 3212  Sally  Smith  Decorator  6.50  Y 43.50

 

Data lines containing Commission based employees begin with a C,  Salaried an S ,  and Hourly an H.  

• Lines that begin with C indicate commission earning employees, These lines contain the employee’s id, first and last name, title, base salary, commission rate, commission threshold, and current sales.

• Lines that begin with S indicate salaried employees, these lines contain the employee’s id, first and last name, title, and salary

• Lines that begin with H are for hourly employees, each line contain the employee’s id, first and last name, title, hourly rate, a Y or N indicating if they can earn overtime, and the hours worked this pay period

• You must read the first character of each line to determine what kind of employee is being processed, and then read the rest of the data

• once the data is read you need to insert an employee object of the right type into your array

• Reading a line of employee data can be accomplished by making multiple calls to scanner methods to extract each individual piece of data 

REMEMBER: depending of the version of Java you have installed, when reading a line of data that ends with a number, class Scanner may not clear the new line character, if this happens  we have to have a dummy read input.nextLine()  to extract it.

 

Testing Tip:

Begin by writing the input loop, read each line of input, and immediately print out the information read.. this will allow you to validate your input

 

As each line of data is read, create an instance of the correct type of employee, then insert it into your array.  The array will accept values of type employee, when an object of type Salaried, Hourly, or CommissionBased is placed into the array, it will be “upcast” to type Employee automatically.

 

 

3. Once all of the employees’ data has been read, and inserted into the array, you will need to sort the array.  You may use any sorting algorithm you wish, including the bubble sort.  

 

4. Finally, it is time to calculate pay, and print the report.  

i. For each employee in your array, loop through all elements applying the calculatePay() method to each

ii. Print the report title, and the column headings for commission based employees.

iii. You will begin looping through all of the employees in your array

iv. While the employee type of the employee retrieved is “C”

1. For each employee call the print() method to print out the object contents.

2. add this employees total Pay to the total pay for all employees of this type

v. When an employee of type hourly, is found, Print the total pay for the previous type, skip a few lines and  then print column headings for hourly employees

vi. While the employee type of the employee is “H”

1. For each employee call the print() method to print out the object contents.

2. add this employees total Pay to the total pay for all employees of this type

vii. When an employee of type salaried is retrieved, Print the total pay for the previous type, skip a few lines then print column headings for salaried employees

1. For each employee call the print() method to print out the object contents.

2. add this employees total Pay to the total pay for all employees of this type

 

 

Once all employees are retrieved print the total pay for salaried employees, and your program is finished.

 

 

Printing the report

 

The report will be divided in to 3 sections based on the three employee types, with the employee data displayed in a columnar format with column headings (use the printf method).  It will have the general format:  

 

Commission Based Employees:

 

First Last Title Employee Commission  Current      Salary Total 

Name Name ID Rate Sales Pay

 

Each section should display the information unique to each employee type, and NOTICE we are conveniently forgetting about taxes, and deductions.  Also your report should have a title, and for each section you should print the “grand total” of the pay due employees of that type.

 

 

What to submit:

Your 5 java files,    submitted in a single ZIP file:

Employee.java

Salaried.java

Hourly.java

Comission.java

TesterClass.java  :  This is what every you call the application class that contains MAIN

 

Need a custom answer at your budget?

This assignment has been answered 2 times in private sessions.

© 2024 Codify Tutor. All rights reserved