Sunday, March 11, 2018

Total salary

Total Salary
Send Feedback

Write a program to calculate the total salary of a person. The user has to enter the basic salary (an integer) and the grade (an uppercase character), and depending upon which the total salary is calculated as -

    totalSalary = basic + hra + da + allow – pf
where :
hra   = 20% of basic
da    = 50% of basic
allow = 1700 if grade = ‘A’
allow = 1500 if grade = ‘B’
allow = 1300 if grade = ‘C' or any other character
pf    = 11% of basic.
Round off the total salary and then print the integral part only.
Input format :
Basic salary & Grade (separated by space)
Output Format :
Total Salary
Sample Input 1 :
10000 A
Sample Output 1 :
17600
Sample Input 2 :
4567 B
Sample Output 2 :

8762


  1. import java.util.Scanner;

  2. public class Main
  3. {

  4. public static void main(String[] args) 
  5. {
  6. double t_sal,allow;
  7. Scanner s = new Scanner(System.in);
  8. //System.out.println("enter the basis amount of salary");
  9. double basic = s.nextInt();
  10. //System.out.println("enter any chr for give grade");
  11. char grade = s.next().charAt(0);
  12. double hra = ((basic*20/100.0));
  13. // System.out.println("hra is "+hra);
  14. double da = ((basic*50/100.0));
  15. // System.out.println("da is "+da);
  16. double pf = ((basic*11/100.0));
  17. // System.out.println("pf is "+pf);
  18. if(grade == 'A')
  19. {
  20. allow = 1700;
  21. }
  22. else if(grade == 'B')
  23. {
  24. allow = 1500;
  25. }
  26. else
  27. {
  28. allow = 1300;
  29. }
  30. t_sal = basic + hra + da + allow - pf;
  31. //System.out.println("total salary is "+t_sal);
  32. System.out.println(Math.round(t_sal));

  33.  
  34. }

  35. }


2 comments:

  1. We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
    and friends also message me on instagram ( https://www.instagram.com/dvlpr.u/ )

    ReplyDelete