KEMBAR78
Java Experiment 3 | PDF | Software | Computer Programming
0% found this document useful (0 votes)
45 views8 pages

Java Experiment 3

The document outlines an experiment to develop a Java application that models an Employee class and its subclasses for different academic positions, including Programmer, Assistant Professor, Associate Professor, and Professor. Each subclass calculates and generates pay slips based on basic pay, including allowances and deductions. The application structure is detailed with class definitions and a main application to interactively create employee instances and display their pay slips.
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)
45 views8 pages

Java Experiment 3

The document outlines an experiment to develop a Java application that models an Employee class and its subclasses for different academic positions, including Programmer, Assistant Professor, Associate Professor, and Professor. Each subclass calculates and generates pay slips based on basic pay, including allowances and deductions. The application structure is detailed with class definitions and a main application to interactively create employee instances and display their pay slips.
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
You are on page 1/ 8

EXPERIMENT NO.

: 3

Title of Experiment: Develop a java application with Employee class with Emp_name,
Emp_id, Address, Mail_id, Mobile_no as members. Inherit the classes, Programmer,
Assistant Professor, Associate Professor and Professor from employee class. Add Basic Pay
(BP) as the member of all the inherited classes with 97% of BP as DA, 10% of BP as HRA,
12% of BP as PF, 0.1% of BP for staff club fund. Generate pay slips for the employees with
their gross and net salary

Program: B.Tech CSE Course: Java Programming Lab Semester: IV


Course Code: PCS 251(L)

Page no: ¼

Directory Structure:

EmployeePayroll/
MainApp.java
Employee.java
Programmer.java
AssistantProfessor.java
AssociateProfessor.java
Professor.java

Employee.java:

public class Employee {


protected String empName;
protected String empId;
protected String address;
protected String mailId;
protected String mobileNo;

Page 11
public Employee(String empName, String empId, String address, String mailId, String
mobileNo) {
this.empName = empName;
this.empId = empId;
this.address = address;
this.mailId = mailId;
this.mobileNo = mobileNo;
}

public void displayDetails() {


System.out.println("Employee Name: " + empName);
System.out.println("Employee ID: " + empId);
System.out.println("Address: " + address);
System.out.println("Mail ID: " + mailId);
System.out.println("Mobile No: " + mobileNo);
}
}

Programmer.java:

public class Programmer extends Employee {


private double basicPay;

public Programmer(String empName, String empId, String address, String mailId, String
mobileNo, double basicPay) {
super(empName, empId, address, mailId, mobileNo);
this.basicPay = basicPay;
}

Page 12
public void generatePaySlip() {
double da = 0.97 * basicPay; // Dearness Allowance
double hra = 0.10 * basicPay; // House Rent Allowance
double pf = 0.12 * basicPay; // Provident Fund
double staffClubFund = 0.001 * basicPay; // Staff Club Fund
double grossSalary = basicPay + da + hra;
double netSalary = grossSalary - (pf + staffClubFund);

System.out.println("\n--- Programmer Pay Slip ---");


displayDetails();
System.out.println("Basic Pay: " + basicPay);
System.out.println("DA (97%): " + da);
System.out.println("HRA (10%): " + hra);
System.out.println("PF (12%): " + pf);
System.out.println("Staff Club Fund (0.1%): " + staffClubFund);
System.out.println("Gross Salary: " + grossSalary);
System.out.println("Net Salary: " + netSalary);
}
}

AssistantProfessor.java:

public class AssistantProfessor extends Employee {


private double basicPay;

public AssistantProfessor(String empName, String empId, String address, String mailId,


String mobileNo, double basicPay) {
super(empName, empId, address, mailId, mobileNo);
this.basicPay = basicPay;
}
Page 13
public void generatePaySlip() {
double da = 0.97 * basicPay;
double hra = 0.10 * basicPay;
double pf = 0.12 * basicPay;
double staffClubFund = 0.001 * basicPay;
double grossSalary = basicPay + da + hra;
double netSalary = grossSalary - (pf + staffClubFund);

System.out.println("\n--- Assistant Professor Pay Slip ---");


displayDetails();
System.out.println("Basic Pay: " + basicPay);
System.out.println("DA (97%): " + da);
System.out.println("HRA (10%): " + hra);
System.out.println("PF (12%): " + pf);
System.out.println("Staff Club Fund (0.1%): " + staffClubFund);
System.out.println("Gross Salary: " + grossSalary);
System.out.println("Net Salary: " + netSalary);
}
}

AssociateProfessor.java:

public class AssociateProfessor extends Employee {


private double basicPay;

public AssociateProfessor(String empName, String empId, String address, String mailId,


String mobileNo, double basicPay) {
super(empName, empId, address, mailId, mobileNo);

Page 14
this.basicPay = basicPay;
}

public void generatePaySlip() {


double da = 0.97 * basicPay;
double hra = 0.10 * basicPay;
double pf = 0.12 * basicPay;
double staffClubFund = 0.001 * basicPay;
double grossSalary = basicPay + da + hra;
double netSalary = grossSalary - (pf + staffClubFund);

System.out.println("\n--- Associate Professor Pay Slip ---");


displayDetails();
System.out.println("Basic Pay: " + basicPay);
System.out.println("DA (97%): " + da);
System.out.println("HRA (10%): " + hra);
System.out.println("PF (12%): " + pf);
System.out.println("Staff Club Fund (0.1%): " + staffClubFund);
System.out.println("Gross Salary: " + grossSalary);
System.out.println("Net Salary: " + netSalary);
}
}

Professor.java:

public class Professor extends Employee {


private double basicPay;

Page 15
public Professor(String empName, String empId, String address, String mailId, String
mobileNo, double basicPay) {
super(empName, empId, address, mailId, mobileNo);
this.basicPay = basicPay;
}

public void generatePaySlip() {


double da = 0.97 * basicPay;
double hra = 0.10 * basicPay;
double pf = 0.12 * basicPay;
double staffClubFund = 0.001 * basicPay;
double grossSalary = basicPay + da + hra;
double netSalary = grossSalary - (pf + staffClubFund);

System.out.println("\n--- Professor Pay Slip ---");


displayDetails();
System.out.println("Basic Pay: " + basicPay);
System.out.println("DA (97%): " + da);
System.out.println("HRA (10%): " + hra);
System.out.println("PF (12%): " + pf);
System.out.println("Staff Club Fund (0.1%): " + staffClubFund);
System.out.println("Gross Salary: " + grossSalary);
System.out.println("Net Salary: " + netSalary);
}
}

MainApp.java:

import java.util.Scanner;

Page 16
public class MainApp {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter Employee Name:");


String name = scanner.nextLine();
System.out.println("Enter Employee ID:");
String id = scanner.nextLine();
System.out.println("Enter Employee Address:");
String address = scanner.nextLine();
System.out.println("Enter Employee Mail ID:");
String mailId = scanner.nextLine();
System.out.println("Enter Employee Mobile No:");
String mobileNo = scanner.nextLine();
System.out.println("Enter Basic Pay:");
double basicPay = scanner.nextDouble();

System.out.println("Choose Designation:\n1. Programmer\n2. Assistant Professor\n3.


Associate Professor\n4. Professor");
int choice = scanner.nextInt();

switch (choice) {
case 1 -> new Programmer(name, id, address, mailId, mobileNo,
basicPay).generatePaySlip();
case 2 -> new AssistantProfessor(name, id, address, mailId, mobileNo,
basicPay).generatePaySlip();
case 3 -> new AssociateProfessor(name, id, address, mailId, mobileNo,
basicPay).generatePaySlip();
case 4 -> new Professor(name, id, address, mailId, mobileNo,
basicPay).generatePaySlip();

Page 17
default -> System.out.println("Invalid choice.");
}

scanner.close();
}
}

Output:

java MainApp

Page 18

You might also like