javaprograms

define class employee with following specification data members : name,empno,basic, da,hra,gross,tax

1) write a parameterized constructor to inintialise the data members 2) to accept details of an employee 3) compute annual salary,if salary exceeds 180000 they " income tax to be paid "
else "no income tax" da=30% of basic hra=13% of basic gross= basic+da+hra salary=12*gross

View Answers

September 28, 2011 at 4:37 PM

import java.util.*;
class Employee 
{
 String name;
 int empno;
 int basic;
 double da;
 double hra;
 double gross;
 int tax;

Employee(String name, int empno,int basic,double da,double hra,double gross,int tax){
    this.name=name;
    this.empno=empno;
    this.basic=basic;
    this.da=da;
    this.hra=hra;
    this.gross=gross;
    this.tax=tax;
}
public void calculateSalary(){

         double salary=12*gross;
         System.out.println("Annual Salary of "+name+" is: "+salary);
         if(salary>180000){
             double taxpaid=(tax/100)* salary;
             System.out.println("Tax to be paid is: "+taxpaid);
         }
         else{
              System.out.println("No Income Tax.");
         }

}
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        System.out.print("Enter Name: ");
        String name=input.nextLine();
        System.out.print("Enter Empno: ");
        int empno=input.nextInt();
        System.out.print("Enter Basic: ");
        int basic=input.nextInt();
        System.out.print("Enter DA: ");
        int da=input.nextInt();
        System.out.print("Enter HRA: ");
        int hra=input.nextInt();
        System.out.print("Enter Tax: ");
        int tax=input.nextInt();
        double tda=basic*.30;
        double thra=basic*.13;
        double gross=tda+thra+basic;
        Employee e=new Employee(name,empno,basic,tda,thra,gross,tax);
        e.calculateSalary();
        }
}









Related Tutorials/Questions & Answers:
Advertisements