Page 259 - Computer science 868 Class 12
P. 259

Program 9      WAP in Java for the following specifications:
                                 Class                           :   Empl
                                 Data Members                    :    Emp_No, Name, Basic Salary, DA, HRA, TA, PF, Gross Salary
                                 Member Methods
                                 Empl (String, String, double)    :   Parameterised constructor to assign instance variable
                                 calcu()                         :    To  calculate  the  Gross  Salary  based  on  the  following
                                                                    condition:
                                 Basic Salary         DA(%)          TA(%)            HRA(%)           PF(%)
                                 >=20,000             53             12               10               8
                                 >=10,000 to <20,000   45            10               12               7.5
                                 < 10,000             40             8 y              14               7
                                 Gross Salary = (Basic Salary + DA + TA + HRA) – PF
                                 display()                       :   To display the data in the following format:
                                 EMPLOYEE No.         NAME           GROSS SALARY         PF
                                 -----                -----          -----                -----
                                 Write  a  main method to  create  an object  of the above  class and call the above  method to
                                 calculate and print the Employee No., Name, Gross Salary and PF of an employee.

                   1      import java.util.*;
                   2      class Empl

                   3      {
                   4          int Emp_No;

                   5          String Name;
                   6          double basic,DA, HRA, TA, PF, gross;

                   7          Empl(int en, String n, double ba) // parameterised Constructor
                   8          {

                   9              Emp_No=en;
                  10              Name=n;

                  11              basic=ba;
                  12          }

                  13
                  14          void calcu()

                  15          {
                  16              if(basic>=20000)

                  17              {
                  18                  DA=53/100.0*basic;

                  19                  TA=12/100.0*basic;
                  20                  HRA=10/100.0*basic;

                  21                  PF=8/100.0*basic;
                  22              }



                                                                                                                       257
                                                                                                            Methods    257
   254   255   256   257   258   259   260   261   262   263   264