Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
Java Program to Calculate PF in 2 Ways | Java Programs
Latest :

Java Program to Calculate PF in 2 Ways | Java Programs

Java Program to Calculate PF – in 2 ways. In this problem, we need to find the gross salary and providential fund for our given input values.

Gross salary is found by subtracting provident fund (pf) from cost-to-company.

For this, our required inputs are basic pay amount (basicpay), percentage of dearness allowance (da), percentage of house rental allowance (hra), percentage of travelling allowance (ta) and percentage of providential fund (pf). All these input values are either money or in percentage so can be fractional. So, we make use of type double.

To read all our inputs at runtime, we will be making use of Scanner class in Java. They are very useful for reading inputs of any primitive type like int, float, long, double, char, etc at runtime. For making use of this, we will require to first create an object for this class. Since all our inputs are of double format, for all of them we invoke the nextDouble() method of Scanner class to read input at runtime as follows:

Scanner s= new Scanner(System.in);

System.out.println(“Enter BASIC PAY AMOUNT”);

basicpay=s.nextDouble();

System.out.println(“Enter the DEARNESS ALLOWANCE %:”);

da=s.nextDouble();

System.out.println(“Enter the HOUSE RENTAL ALLOWANCE %:”);

hra=s.nextDouble();

System.out.println(“Enter the TRAVELLING ALLOWANCE %:”);

ta=s.nextDouble();

System.out.println(“Enter the PROVIDENTAIL FUND %:”);

pf=s.nextDouble();

After getting all our necessary inputs, we will need to find the gross salary. To determine the gross salary the formula to be used is as below:

grosssalary=basicpay*(100+da+hra+ta-pf)*0.01;

or can also be written as,

grosssalary=basicpay*(100+da+hra+ta-pf)/100;

Just as the definition of gross salary states, we subtract the providential funds from our cost to company.

To find the providential fund is very easy. We only require the basicpay and the percentage of providential fund. The amount for providential fund is calculated as follows:

amount for providential fund= basicpay*pf*0.01

(or)

amount for providential fund= basicpay*pf/100

The final outputs can be displayed on the console screen by making use of System.out.println() method for displaying in the new line every time.

System.out.println(“Gross salary”+ grosssalary);

System.out.println(“PF amount is:”+ basicpay*pf*0.01);

 

Output:

 

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)
x

Check Also

Java Right Arrow Star Pattern Program | Patterns

Java program to print Right Arrow star pattern program. We have written the below print/draw ...