Java program to create payslip for employees by using Inheritance

/*QUESTION:

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 

import java.util.Scanner;

class Employee

{

    String emp_name,address,mail_id,mobile_no;

    int emp_id;

    double grosssalary=0,netsalary=0;

    public void getdata()

    {

    Scanner Sc=new Scanner(System.in);

    System.out.print("Enter the Employee id :");

    emp_id=Sc.nextInt();

    System.out.print("Enter the Employee Name:");

    emp_name=Sc.next();

    System.out.print("Enter the Address :");

    address=Sc.next();

    System.out.print("Enter the Mail_Id :");

    mail_id=Sc.next();

    System.out.print("Enter the Mobile Number:");

    mobile_no=Sc.next();

    }

    public void Showdata()

    {

    System.out.println("________________________________");

    System.out.println("Emp_id \t Emp_name \t Address \t Mail_id \t Mobile_no \t Grosssalary\t Netsalary");

    System.out.println(emp_id+" \t "+emp_name+"\t"+address+"\t"+mail_id+"\t"+mobile_no+"\t "+grosssalary+"\t "+netsalary);

    System.out.println("________________________________");

    }

}

class Manager extends Employee

{

    int BP=30000;

    double DA,HRA,PF;

    public void calculate()

    {

         DA=BP*0.5;

         HRA=BP*0.1;

         PF=BP*0.02;

    grosssalary=BP+ DA +HRA;

    netsalary=grosssalary-PF;

    }

    public void manager()

    {

    System.out.println("Basic Pay = "+BP);

    System.out.println("Dearness Allowance = "+DA);

    System.out.println("HouseRent Allowance = "+HRA);

    System.out.println("Provident Fund = "+PF);

    }

}

class Clerk extends Employee

{

    int BP=20000;

    double DA,HRA,PF;

    public void calculate()

    {

         DA=0.25*BP;

         HRA=0.05*BP;

         PF=0.06*BP;

    }

    public void clerk()

    {

    System.out.println("Basic Pay = "+BP);

    System.out.println("Dearness Allowance = "+DA);

    System.out.println("HouseRent Allowance = "+HRA);

    System.out.println("Provident Fund = "+PF);

    grosssalary=BP+DA+HRA;

    netsalary=grosssalary-PF;

    }

}

public class Experiment3

{

    public static void main(String[] args) {

    Manager m = new Manager();

    Clerk c = new Clerk();

    System.out.println("-----ENTER THE DETAILS OF MANAGER-----");

    m.getdata();

    m.calculate();

    System.out.println("-----ENTER THE DETAILS OF CLERK-----");

    c.getdata();

    c.calculate();

    System.out.println("*******");

    System.out.println("\n\n-----PAY SLIP FOR MANAGER-----");

    m.manager();

    m.Showdata();

    System.out.println("\nn-----PAY SLIP FOR CLERK-----");

    c.clerk();

    c.Showdata();

}

}


Comments

Popular Posts