Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

JAVA (CSE310) PROJECT REPORT

TOPIC: EMPLOYEE PAYROLL SYSTEM

MEMBERS:

NAME REGN NO. ROLL NO.

SAGNIK PANDA 12100867 RK21PDA05

NIKHIL SATYAM 12100798 RK21PDA06

SWETABH SEKHAR 12109743 RK21PDA04

UNDER THE GUIDANCE OF OUR TEACHER:


PUNEET KUMAR

SUBMITTED TO: -
“SCHOOL OF COMPUTER SCIENCE AND ENGENEERING”
INTRODUCTION

The Employee Payroll Management System is a software or application that is


designed to manage and streamline the process of paying employees in an
organization. It is an essential tool for businesses of all sizes, helping them
efficiently calculate and process employee salaries, wages, taxes, and other
compensation-related expenses.

The system is typically used by HR and payroll departments within an


organization, and it automates various tasks related to employee payroll
management, such as calculating employee salaries based on hours worked,
managing deductions, generating pay stubs, and generating payroll reports for
compliance and record-keeping purposes.

The Employee Payroll Management System simplifies the complex process of


managing employee payroll, ensuring accuracy, efficiency, and compliance
with applicable labour laws and tax regulations. It minimizes the risk of errors
in calculating employee compensation and helps maintain confidentiality and
security of payroll information. It also saves time and effort by automating
routine tasks, reducing manual intervention, and providing comprehensive
reporting and analytics for better decision-making.

Key features of an Employee Payroll Management System may include


employee data management, time and attendance tracking, tax calculation and
reporting, benefits and deductions management, payroll processing, direct
deposit or pay check printing, leave management, payroll tax filing, and
reporting and analytics.

Overall, an Employee Payroll Management System is an essential tool for


organizations to manage their payroll processes efficiently, ensure compliance
with labour laws and tax regulations, and maintain accurate and confidential
payroll records for their employees.
OBJECTIVE

 Efficiency: The system aims to automate and simplify the complex and
time-consuming process of calculating and managing employee salaries,
wages, taxes, and other compensation-related expenses. It reduces the
manual effort involved in payroll processing, minimizes the risk of errors,
and improves overall efficiency in managing payroll tasks.

 Accuracy: The system aims to ensure accurate calculation of employee


compensation, including wages, deductions, and taxes, based on
predefined rules and regulations. It reduces the risk of human errors in
payroll processing, which can lead to costly mistakes and legal
compliance issues.

 Compliance: The system aims to ensure compliance with applicable


labour laws, tax regulations, and other statutory requirements related to
payroll management. It helps organizations stay updated with changing
regulations, calculates taxes accurately, and generates reports for
compliance and record-keeping purposes.

 Confidentiality and Security: The system aims to maintain the


confidentiality and security of employee payroll information. It provides
access controls, data encryption, and other security measures to protect
sensitive payroll data from unauthorized access and breaches.

 Reporting and Analytics: The system aims to provide comprehensive


reporting and analytics features that allow organizations to gain insights
into their payroll data. It generates various reports, such as payroll
registers, tax reports, and employee compensation summaries, which
can help organizations make informed decisions related to payroll
management and budgeting.
ABOUT JAVA

Java is a popular, versatile, and widely-used programming language known for


its platform independence, robustness, and scalability. Developed by Sun
Microsystems (now owned by Oracle), Java was released in 1995 and has since
become one of the most widely used programming languages for a wide range
of applications, from desktop software to web applications, mobile apps, and
enterprise systems.

Java is an object-oriented programming language that follows the "write once,


run anywhere" (WORA) principle, which means that Java code can be written
on one platform and run on multiple platforms without requiring any
modifications. Java applications are typically compiled into an intermediate
form called Java bytecode, which can be interpreted and executed by the Java
Virtual Machine (JVM) on various operating systems, making Java highly
portable.

Java offers a rich set of libraries and frameworks that provide extensive
functionality for tasks such as graphical user interface (GUI) development,
networking, database connectivity, multithreading, and more. Java also
supports concurrent programming, allowing developers to write efficient and
scalable applications that can handle multiple tasks simultaneously.
SOURCE CODE

EMPLOYEE CLASS :
public class Employee {
private String name;
private double salary;
private double taxRate;
private double niRate;
private double taxPaid;

public Employee(String name, double salary, double taxRate, double niRate) {


this.name = name;
this.salary = salary;
this.taxRate = taxRate;
this.niRate = niRate;
this.taxPaid = 0;
}

public double calculateTax() {


double annualSalary = salary * 12;
double annualTax = annualSalary * (taxRate / 100);
taxPaid += annualTax;
return annualTax;
}
public double getTaxRate() {
return taxRate;
}
public double getniRate() {
return niRate;
}
public double getTaxPaid() {
return taxPaid;
}
public double getNetPay() {
double nitax = (salary * niRate)/100;
double tax = nitax + (salary * taxRate)/100;
double netPay = salary - tax;
return netPay;
}

public double getGrossPay() {


return salary;
}

public String getName() {


return name;
}

public String toString() {


return "<< Name: " + name + "|| Gross Pay: " + getGrossPay() + "|| Net Pay: " +
getNetPay()+" >>";
}
}

PAYROLLSYSTEM CLASS :
import java.util.*;
import java.io.*;

public class PayrollSystem {


private List<Employee> employees = new ArrayList<>();
private final String FILENAME = "employees.txt";

public PayrollSystem() {
employees = new ArrayList<Employee>();
}

public void addEmployee(Employee employee) {


employees.add(employee);
}

public void deleteEmployee(String name) {


boolean removed = false;
Iterator<Employee> iter = employees.iterator();
while (iter.hasNext()) {
Employee employee = iter.next();
if (employee.getName().equals(name)) {
iter.remove();
System.out.println("Employee " + name + " has been removed.");
removed = true;
}
}
if (!removed) {
System.out.println("Employee " + name + " not found.");
return;
}
List<String> temp = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(FILENAME))) {
String line;
while ((line = reader.readLine()) != null) {
String[] tokens = line.split(",");
if (!tokens[0].equals(name)) {
temp.add(line);
}
}
} catch (IOException e) {
System.out.println("Error reading from " + FILENAME);
return;
}
try (PrintWriter writer = new PrintWriter(new FileWriter(FILENAME))) {
for (String line : temp) {
writer.println(line);
}
System.out.println("Employee details saved to " + FILENAME);
} catch (IOException e) {
System.out.println("Error writing to " + FILENAME);
}
}

public Employee findEmployee(String name) {


for (Employee employee : employees) {
if (employee.getName().equals(name)) {
return employee;
}
}
return null;
}
public void displayPaySlip(String name) {
Employee employee = findEmployee(name);
if (employee != null) {
System.out.println(employee.toString());
} else {
System.out.println("Employee not found.");
}
}

private void saveEmployeesToFile() {


try (PrintWriter writer = new PrintWriter(new FileWriter(FILENAME))) {
for (Employee employee : employees) {
writer.println(employee.getName() + "," + employee.getGrossPay() + "," +
employee.getTaxRate() + ","
+ employee.getniRate());
}
} catch (IOException e) {
System.err.println("Error saving employees to file: " + e.getMessage());
}
}

private void loadEmployeesFromFile() {


try (Scanner scanner = new Scanner(new File(FILENAME))) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] fields = line.split(",");
if (fields.length == 4) {
String name = fields[0];
double salary = Double.parseDouble(fields[1]);
double taxRate = Double.parseDouble(fields[2]);
double niRate = Double.parseDouble(fields[3]);
Employee employee = new Employee(name, salary, taxRate, niRate);
employees.add(employee);
}
}
} catch (FileNotFoundException e) {
System.out.println("No employee data found.");
}
}

public static void main(String[] args) {

PayrollSystem payrollSystem = new PayrollSystem();


payrollSystem.loadEmployeesFromFile();

Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("Enter a operation:");
System.out.println("1. Add Employee");
System.out.println("2. Delete Employee");
System.out.println("3. Display Pay Slip");
System.out.println("4. Save to File");
System.out.println("5. Exit");
System.out.println("========================================");
System.out.println("Enter a choice:");
int choice = scanner.nextInt();
scanner.nextLine();
System.out.println("========================================");

if (choice == 1) {
System.out.print("Enter name of employee: ");
String name = scanner.nextLine();
System.out.print("Enter salary of employee: ");
double salary = scanner.nextDouble();
System.out.print("Enter tax rate of employee (in decimal): ");
double taxRate = scanner.nextDouble();
System.out.print("Enter National Insurance Rate of employee (in decimal[0.x]): ");
double niRate = scanner.nextDouble();
Employee employee = new Employee(name, salary, taxRate, niRate);
payrollSystem.addEmployee(employee);
System.out.println("Employee added successfully.");
} else if (choice == 2) {
System.out.print("Enter name of employee to delete: ");
String name = scanner.nextLine();
payrollSystem.deleteEmployee(name);
System.out.println("Employee deleted successfully.");
} else if (choice == 3) {
System.out.print("Enter name of employee to display pay slip: ");
String name = scanner.nextLine();
System.out.println("========================================");
payrollSystem.displayPaySlip(name);
System.out.println("========================================");
} else if (choice == 4) {
payrollSystem.saveEmployeesToFile();
System.out.println("Data saved to file.");
} else if (choice == 5) {
payrollSystem.saveEmployeesToFile();
System.out.println("Data saved to file.");
System.out.println("Exiting...");
break;
} else {
System.out.println("Invalid choice. Please try again.");
}
}
scanner.close();

}
}

// This code defines two classes, Employee and PayrollSystem.


//The Employee class stores information about an individual employee,
//including their name, salary, tax rate, and national insurance (NI) rate.//
// The PayrollSystem class manages a list of employees and provides methods
for adding employees,
// finding employees by name, and displaying pay slips for individual
employees.
// The displayPaySlip method takes an employee's name as an argument and
prints out a formatted string
// displaying their name, gross pay, and net pay. The net pay is calculated by
subtracting taxes from gross pay

TERMINAL OUTPUT :
Enter a operation:
1. Add Employee
2. Delete Employee
3. Display Pay Slip
4. Save to File
5. Exit
========================================
Enter a choice:
1
========================================
Enter name of employee: Mungeri Lal
Enter salary of employee: 50000
Enter tax rate of employee (in decimal): 5
Enter National Insurance Rate of employee (in decimal[0.x]): 0.9
Employee added successfully.
Enter a operation:
1. Add Employee
2. Delete Employee
3. Display Pay Slip
4. Save to File
5. Exit
========================================
Enter a choice:
3
========================================
Enter name of employee to display pay slip: Mungeri Lal
========================================
<< Name: Mungeri Lal|| Gross Pay: 50000.0|| Net Pay: 47050.0 >>
========================================
Enter a operation:
1. Add Employee
2. Delete Employee
3. Display Pay Slip
4. Save to File
5. Exit
========================================
Enter a choice:
5
========================================
Data saved to file.
Exiting...

Screenshots of Output:
Content in Employees.txt after operations:
CONSLUSION

In conclusion, the code demonstrates the use of a Payroll class to generate pay
slips for employees. Two employee objects, employee1 and employee2, are
created with their respective details such as name, address, salary, and tax
deductions. These employee objects are then added to the payroll using the
addEmployee() method. The generatePaySlips() method is called on the payroll
object to generate an ArrayList of PaySlip objects, which contain information
such as the employee name, gross pay, tax deduction, national insurance
deduction, and net pay. Finally, a loop iterates through the pay slips and prints
out the details of each pay slip using the get methods of the PaySlip class. This
code showcases an example of how a payroll system can be implemented in
Java using classes and objects.
the PayrollSystem class is a Java program that provides functionality for
managing employees' payroll information. It allows users to add employees,
delete employees, display pay slips, and save employee data to a file. The
program makes use of a list to store employee objects and reads from and
writes to a text file for persistence of employee data.
The program also handles exceptions, such as FileNotFoundException and
IOException, which may occur when reading from or writing to the employee
data file. The PayrollSystem class uses try-with-resources to properly manage
resources such as FileReader, BufferedReader, FileWriter, and PrintWriter to
ensure efficient and safe handling of file operations.

You might also like