0% found this document useful (0 votes)
36 views7 pages

Pay Slip Generation in Java

1. The document describes a Java program that generates pay slips for different categories of employees using inheritance. 2. It creates an Employee class with common attributes and inherits classes like Programmer, Assistant Professor, Associate Professor, and Professor from the Employee class. 3. These inherited classes calculate attributes like DA, HRA, PF, gross salary, and net salary in the same way and generate pay slips by displaying the values.

Uploaded by

5052 - UTHRA .T
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Pay Slip Generation in Java

1. The document describes a Java program that generates pay slips for different categories of employees using inheritance. 2. It creates an Employee class with common attributes and inherits classes like Programmer, Assistant Professor, Associate Professor, and Professor from the Employee class. 3. These inherited classes calculate attributes like DA, HRA, PF, gross salary, and net salary in the same way and generate pay slips by displaying the values.

Uploaded by

5052 - UTHRA .T
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

UTHRA.

T
311520205052
EX NO: PAYSLIP GENERATION USING INHERITANCE
DATE:

AIM:
To develop a java application to generate pay slip for different category of employees using the
concept of

inheritance.

ALGORITHM:

1. Start
2. Create the class Employee with name, Empid, address, mailid, mobileno as data members.
3. Inherit the classes Programmer, Asstprofessor, Associateprofessor and
Professor from employee class.
4. Add Basic Pay (BP) as the member of all the inherited classes.
5. Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of
BP.
6. Calculate gross salary and net salary.
7. Generate payslip for all categories of employees.
8. Create the objects for the inherited classes and invoke the necessary methods to display the
Payslip
9. Stop

PROGRAM:

[Link]
import
[Link].*;
class
Employee
{
int empid;
long
mobile;
String name, address, mailid;
Scanner get = new
Scanner([Link]); void
getdata()
{
[Link]("Enter Name of the
Employee"); name = [Link]();
[Link]("Enter
Mail id"); mailid =
[Link]();
[Link]("Enter Address of the
Employee:"); address = [Link]();
[Link]("Enter employee
id "); empid = [Link]();
[Link]("Enter Mobile
Number"); mobile = [Link]();
}
void display()
UTHRA.T
311520205052
{
[Link]("Employee Name:
"+name); [Link]("Employee
id : "+empid); [Link]("Mail
id : "+mailid);
[Link]("Address:
"+address); [Link]("Mobile
Number: "+mobile);
}
}

class Programmer extends Employee


{
double
salary,bp,da,hra,pf,club,net,gross;
void getprogrammer()
{
[Link]("Enter basic
pay"); bp = [Link]();
}

void calculateprog()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+h
ra); net=(gross-
pf-club);
[Link]("***********************************
*********"); [Link]("PAY SLIP FOR
PROGRAMMER");
[Link]("***********************************
*********"); [Link]("Basic Pay: Rs. "+bp);
[Link]("DA: Rs. "+da);
[Link]("HRA: Rs. "+hra);
[Link]("PF: Rs. "+pf);
[Link]("CLUB: Rs. "+club);
[Link]("GROSS PAY: Rs.
"+gross); [Link]("NET
PAY: Rs. "+net);
}
UTHRA.T
311520205052
}
class Asstprofessor extends Employee
{
double
salary,bp,da,hra,pf,club,net,gross;
void getasst()
{
[Link]("Enter basic
pay"); bp = [Link]();
}
void calculateasst()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+h
ra); net=(gross-
pf-club);
[Link]("*****************************
******"); [Link]("PAY SLIP FOR
ASSISTANT PROFESSOR");
[Link]("****************************
*******"); [Link]("Basic Pay: Rs. "+bp);
[Link]("DA: Rs. "+da);
[Link]("HRA: Rs. "+hra);
[Link]("PF: Rs. "+pf);
[Link]("CLUB: Rs. "+club);
[Link]("GROSS PAY: Rs.
"+gross); [Link]("NET
PAY: Rs. "+net);
}
}
class Associateprofessor extends Employee
{
double
salary,bp,da,hra,pf,club,net,gross;
void getassociate()
{
[Link]("Enter basic
pay"); bp = [Link]();
}
void calculateassociate()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+h
ra); net=(gross-
pf-club);
UTHRA.T
311520205052
[Link]("*****************************
******"); [Link]("PAY SLIP FOR
ASSOCIATE PROFESSOR");
[Link]("****************************
*******"); [Link]("Basic Pay: Rs. "+bp);
[Link]("DA: Rs. "+da);
[Link]("HRA: Rs. "+hra);
[Link]("PF: Rs. "+pf);
[Link]("CLUB: Rs. "+club);
[Link]("GROSS PAY: Rs.
"+gross); [Link]("NET
PAY: Rs. "+net);
}
}
class Professor extends Employee
{
double
salary,bp,da,hra,pf,club,net,gross;
void getprofessor()
{
[Link]("Enter basic
pay"); bp = [Link]();
}
void calculateprofessor()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+h
ra); net=(gross-
pf-club);
[Link]("*******************
*****"); [Link]("PAY SLIP
FOR PROFESSOR");
[Link]("*******************
*****"); [Link]("Basic Pay: Rs.
"+bp); [Link]("DA: Rs. "+da);
[Link]("HRA: Rs. "+hra);
[Link]("PF: Rs. "+pf);
[Link]("CLUB: Rs. "+club);
[Link]("GROSS PAY: Rs.
"+gross); [Link]("NET PAY:
Rs. "+net);
}
}
class Salary
{
public static void main(String args[])
{
int
choice,cont;
do
{
[Link]("PAYROLL");
UTHRA.T
311520205052
[Link](" [Link] \t [Link] PROFESSOR \t
[Link] PROFESSOR \t [Link] ");
Scanner c = new
Scanner([Link]);
[Link](“Enter Your
Choice:”); choice=[Link]();
switch(choice)
{

Case 1:

{
Programmer p=new
Programmer(); [Link]();
[Link]
r(); [Link]();
[Link](
} ); break;
UTHRA.T
311520205052
case
2:
{ Asstprofessor asst=new
Asstprofessor(); [Link]();
[Link]();
[Link]();
[Link]
t(); break;
}
case
3:
{ Associateprofessor asso=new
Associateprofessor(); [Link]();
[Link]();
[Link]();
[Link]
te(); break;
}
case
4:
{ Professor prof=new
Professor(); [Link]();
[Link]();
[Link]();
[Link]();
break;
}
}
[Link]("Please enter 0 to quit and 1 to
continue: "); cont=[Link]();
}while(cont==1);
}
}

OUTPUT
UTHRA.T
311520205052

RESULT
Thus the Java application to generate pay slip for different category of employees
was implemented using inheritance and the program was executed successfully.

Common questions

Powered by AI

The application calculates gross pay by summing the basic pay (BP), Dearness Allowance (DA), and House Rent Allowance (HRA). Net pay is calculated by deducting Provident Fund (PF) and Staff Club fund from the gross pay. These figures are critical as they represent the total earnings before deductions (gross pay) and the final amount disbursed to the employee (net pay). The distinction between gross and net pay is essential for both accounting and employee financial planning .

The 'getdata' method in the Employee class is used to input basic information about the employee, including their name, email ID, address, employee ID, and mobile number. This method ensures all necessary personal data is collected for all employee types before salary calculations are performed. This data integration allows personalized information to be included in the generated pay slips, thus ensuring the payroll system functions as intended by associating financial computations with the correct individual .

The Java program uses a switch-case statement to facilitate the selection of employee type. The user is prompted to enter their choice (e.g., 1 for Programmer, 2 for Assistant Professor, and so on) via the console input. Based on this numeric choice, the program invokes specific methods associated with the respective employee class (e.g., 'getprogrammer' and 'calculateprog' for a Programmer). This approach allows the program to dynamically generate the appropriate pay slip by directing execution flow to the relevant class methods .

The Java program personalizes pay slips by having separate classes for each category of employee, inheriting from a common Employee class. Each class—Programmer, Assistant Professor, Associate Professor, and Professor—has its own methods for inputting basic pay and computing financial components derived from it, personalizing the calculations and the content of the pay slip. The unified calculation framework is maintained by using the same formulaic structure to compute DA, HRA, PF, and other components for all categories. This approach ensures the pay slips are customized based on employee type while upholding the consistency of calculation methodology .

The Java application could be enhanced by implementing a GUI to replace console input, making it more user-friendly and intuitive. Additionally, expanding upon the data validation processes would prevent errors in employee information. The program could also support database integration to maintain and retrieve historical payroll data, enhancing data storage and accessibility. Introducing additional employee categories or advanced customization features could cater to more nuanced payroll needs. Finally, securing the application against unauthorized access or data breaches would enhance its overall robustness .

The program uses the 'Scanner' class to gather input from the user for salary calculations. This choice allows flexibility as Scanner can parse primitive data types and strings, accommodating different input needs within the payroll application. However, reliance on console input limits batch processing of data typically required for larger payroll systems, impacting scalability and efficiency for larger organizations or more complex workflows .

The program ensures continuity by using a do-while loop that repeatedly executes the pay slip generation process until the user decides to quit. After generating a pay slip, the user is asked to enter '0' to quit or '1' to continue, allowing them to generate additional pay slips for different employees or categories within a single execution session. This loop structure, coupled with user input, seamlessly facilitates multiple pay slip generations within a continuous session .

Inheritance is an appropriate design choice for this payroll program because it provides a convenient way to extend the functionality of the base Employee class to various types of employees. This design allows each specific employee class (Programmer, Assistant Professor, etc.) to inherit common data members and methods from the base class, minimizing redundancy. It also facilitates code reuse and helps in the extension of the application by allowing additional employee categories to be easily added later, enhancing maintainability and scalability of the payroll system .

The program uses a Java class hierarchy where a base class 'Employee' is defined with attributes such as name, employee ID, address, email, and mobile number. Specific categories of employees such as Programmer, Assistant Professor, Associate Professor, and Professor inherit from the Employee class. Each of these derived classes includes methods to input basic pay and calculate additional salary components like DA, HRA, PF, and Staff club fund based on basic pay. This structure allows creation of payroll for each category by calculating gross and net salaries using these percentages. The program integrates this functionality into a user interface using a switch-case statement to choose the category and generate pay slips based on the category-specific salary calculations .

The salary components include Dearness Allowance (DA), House Rent Allowance (HRA), Provident Fund (PF), and Staff club fund. These are derived from the basic pay (BP) as follows: DA is 97% of BP, HRA is 10% of BP, PF is 12% of BP, and Staff club fund is 0.1% of BP. The gross salary is calculated as the sum of BP, DA, and HRA, while the net salary is determined by subtracting PF and the Staff club fund from the gross salary .

You might also like