Computer Science, asked by politecybergamer, 11 hours ago

To input name, and basic salary. Calculate and display the following :
HRA @ 15% of basic salary.
DA @ 70% of basic salary.
TA @ 2% of basic salary.
PF @ 10% of basic salary.
Gross_salary = basic + HRA + DA + TA
Net_salary = gross - PF

Answers

Answered by anindyaadhikari13
3

Solution:

The given problem is solved in Java.

import java.util.Scanner;

public class Main{

   public static void main(String args[]){

       Scanner sc = new Scanner(System.in);

       double basic, hra, da, ta, pf, gross, net;

       System.out.print("Enter basic: ");

       basic = sc.nextDouble();

       sc.close();

       hra = 15 * basic / 100.0;

       da = 70 * basic / 100.0;

       ta = 2 * basic / 100.0;

       pf = 10 * basic / 100.0;

       gross = basic + hra + da + ta;

       net = gross - pf;

       System.out.println("HRA: " + hra);

       System.out.println("DA: " + da);

       System.out.println("TA: " + ta);

       System.out.println("PF: " + pf);

       System.out.println("Gross: " + gross);

       System.out.println("Net:" + net);

   }

}

Explanation:

  • Line 1: Imports Scanner class for taking input.
  • Line 2: Class declaration.
  • Line 3: Main method declaration.
  • Line 4: Objects of scanner class created for taking input.
  • Line 5: Variables required for this problem are created.
  • Line 6: Requested the user to enter the basic salary.
  • Line 7: Basic salary is taken as input.
  • Line 8: Scanner class is closed since input task is finished.
  • Line 9-14: The required values are calculated as per the formula mentioned.
  • Line 15-20: They are now displayed on screen.
  • Line 21: End of main.
  • Line 22: End of class.

Refer to the attachment for output.

Attachments:
Similar questions