Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main{
- public static void main(String[]args){
- Employee e=new Employee();
- e.input();
- CalculateGrossSalary c=new CalculateGrossSalary(e);
- c.showInfo();
- }
- }
- class Employee{
- static Scanner input=new Scanner(System.in);
- private int code;
- private double salary,da,hra;
- private String name;
- public int getCode() {
- return code;
- }
- public double getSalary() {
- return salary;
- }
- public String getName() {
- return name;
- }
- public double getDA(){
- if(this.salary<=10000){
- this.da=this.salary*0.8;
- }
- else if(this.salary<=20000){
- this.da=this.salary*0.9;
- }
- else{
- this.da=this.salary*0.95;
- }
- return this.da;
- }
- public double getHRA(){
- if(this.salary<=10000){
- this.hra=this.salary*0.2;
- }
- else if(this.salary<=20000){
- this.hra=this.salary*0.25;
- }
- else{
- this.hra=this.salary*0.3;
- }
- return this.hra;
- }
- public void input(){
- System.out.print("Enter the employee code:");
- this.code=input.nextInt();
- System.out.print("Enter name:");
- this.name=input.next();
- System.out.print("Enter salary:");
- this.salary=input.nextDouble();
- }
- }
- class CalculateGrossSalary{
- public Employee e;
- public CalculateGrossSalary(Employee e){
- this.e=e;
- }
- public void showInfo(){
- System.out.println("Code:"+e.getCode());
- System.out.println("Name:"+e.getName());
- System.out.println("Salary:"+e.getSalary());
- double gs=e.getSalary()+this.e.getHRA()+this.e.getDA();
- System.out.println("Gross Salary:"+gs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement