Saturday, 11 August 2012

Create a class called Employee that stores its name, department, designation and basic salary.

Create a class called Employee that stores its name, department, designation and basic salary. Write
functions to accept, display and get/set of the data.
The incentives includes HRA, DA , CA.
import java.util.Scanner;


public class Employe {

    protected String name;
    protected String department;
    protected String designation;
    protected float bs;

    public Employe() {

}
public Employe(String name, String department, String designation, float bs) {

this.name = name;
        this.department = department;
        this.designation = designation;
        this.bs = bs;

}

    public String getName() {

return name;
}

    public void setName(String name) {

this.name = name;
}
public String getDepartment() {
return department;

}


public void setDepartment(String department) {
this.department = department;
}
public String getDesignation() {
return designation;
}

    public void setDesignation(String designation) {
this.designation = designation;
}

    public void getData() {
Scanner in = new Scanner(System.in);
System.out.println("Enter name:");
name = in.nextLine();
System.out.println("Enter department:");
department = in.nextLine();
System.out.println("Enter designation:");
designation = in.nextLine();
System.out.println("Enter Basic salary:");
    bs = in.nextInt();
}
public void showData() {
System.out.println("Name is:" + name);

System.out.println("Department is:" + department);
        System.out.println("Designation is:" + designation);
System.out.println("Basic salary is:" + bs);
}


public float getBs() {

return bs;
}


public void setBs(float bs) {
this.bs = bs;

}
public float getHRA() {
        return bs * 20 / 100;
    }


public float getDA() {

return bs * 10 / 100;

}
public float getCA() {
        return bs * 10 / 100;
    }

    public static void main(String[] args) {

        Employe e = new Employe("Vikas", "management", "ceo", 60000);
        e.showData();
        System.out.println("HRA is:" + e.getHRA());
        System.out.println("DA is:" + e.getDA());
System.out.println("CA is:" + e.getCA());
        Employe e1 = new Employe();
        e1.getData();
       e1.showData();
System.out.println("HRA is:" + e1.getHRA());
System.out.println("DA is:" + e1.getDA());
System.out.println("CA is:" + e1.getCA());

}
}

No comments:

Post a Comment