0% found this document useful (0 votes)
4 views3 pages

Q010_Bonus_Calculation_using_Abstract_Class_program in java

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
4 views3 pages

Q010_Bonus_Calculation_using_Abstract_Class_program in java

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Assignment no 10

import java.util.Scanner;

abstract class Employee {


public abstract void CalculateSalary();
}

public class Staff extends Employee {


private int id;
private String name;
private int experience;
private double salary;
private double rating;
private double bonus;

public Staff(int id, String name, int experience, double


salary, double rating) {
this.id = id;
this.name = name;
this.experience = experience;
this.salary = salary;
this.rating = rating;
}

@Override
public void CalculateSalary() {
if (experience >= 0 && experience <= 2) {
bonus = rating * 2000;
} else if (experience > 2 && experience <= 5) {
bonus = rating * 4000;
} else {
bonus = 0;
}
salary += bonus;
displayDetails();
}

private void displayDetails() {


System.out.println("Staff id = " + id + ", name = " +
name + " receives bonus of Rs." + (int) bonus);
System.out.println("Your total salary of this month = " +
(int) salary);
}

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

System.out.println("Calculate bonus of employee based on


rating's provided");
System.out.print("Enter staff id: ");
int id = sc.nextInt();

System.out.print("Enter staff name: ");


sc.nextLine();
String name = sc.nextLine();

System.out.print("Enter years of experience in numbers:


");
int experience = sc.nextInt();

System.out.print("Enter current salary of staff: ");


double salary = sc.nextDouble();

System.out.print("Enter overall rating of staff(out of


10): ");
double rating = sc.nextDouble();

Staff staff = new Staff(id, name, experience, salary,


rating);
staff.CalculateSalary();

sc.close();
}
}
Output:

Calculate bonus of employee based on rating's provided


Enter staff id:
101
Enter staff name:
Aliza Khan
Enter years of experience in numbers:
2
Enter current salary of staff:
15500
Enter overall rating of staff(out of 10)
3
Staff id = 101, name = Aliza Khan receives bonus of Rs.6000
Your total salary of this month = 21500

Sample Input and Output 2:


Calculate bonus of employee based on rating's provided
Enter staff id:
222
Enter staff name:
Priyanka Tripathy
Enter years of experience in numbers:
3
Enter current salary of staff:
20000
Enter overall rating of staff(out of 10)
4
Staff id = 222, name = Priyanka Tripathy receives bonus of Rs.16000
Your total salary of this month = 36000

Sample Input and Output 3:


Calculate bonus of employee based on rating's provided
Enter staff id:
104
Enter staff name:
Kunal
Enter years of experience in numbers:
1
Enter current salary of staff:
12000
Enter overall rating of staff(out of 10)
4
Staff id = 104, name = Kunal receives bonus of Rs.8000
Your total salary of this month = 20000

You might also like