Saturday, 7 February 2015

[JAVA] [ICSE 2005 Answer 4] Finding Salary

Question:
ICSE 2005 Question 4
Write a class with name 'employee' and basic as its data member, to find the gross pay of an employee of the following allowances and deduction. Use meaning ful variable.
Dearness Allowance = 25% of Basic pay
House Rent Allowance = 15% of Basic pay
Provident Fund = 8.33% of Basic pay
Net Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Gross Pay = Net Pay - Provident Fund

Source Code:
class employee
{
    double basic;
    public void find(double basic)throws Exception
    {
        this.basic=basic;
        double da=25.0/100.0*basic;
        double hra=15.0/100.0*basic;
        double pf=8.33/100.0*basic;
        double np=basic+da+hra;
        double gp=np-pf;
        System.out.println("Dearness Allowance = Rs. "+da+"\nHouse Rent Allowance = Rs. "+hra+"\nProvident Fund = Rs. "+pf+"\nNet Pay = Rs. "+np+"\nGross Pay = Rs. "+gp);
    }

}

Result:
INPUT:
20810
OUTPUT:
Dearness Allowance = Rs. 5202.5
House Rent Allowance = Rs. 3121.5
Provident Fund = Rs. 1733.473
Net Pay = Rs. 29134.0
Gross Pay = Rs. 27400.527000000002

No comments:

Post a Comment