-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee_salary_management.java
More file actions
48 lines (39 loc) · 1.31 KB
/
Employee_salary_management.java
File metadata and controls
48 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Employee {
String name;
int id;
double salary;
Employee(String name, int id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
double calculateGrossSalary() {
double hra = salary * 0.2;
double allowances = salary * 0.1;
return salary + hra + allowances;
}
void applyBonus(double bonus) {
salary += bonus;
}
void printSalaryDetails() {
System.out.println("Employee Name: " + name);
System.out.println("Employee ID: " + id);
System.out.println("Salary: " + salary);
}
}
public class Main {
public static void main(String[] args) {
Employee employee1 = new Employee("John", 101, 30000);
Employee employee2 = new Employee("Jane", 102, 35000);
System.out.println("Before Bonus:");
employee1.printSalaryDetails();
employee2.printSalaryDetails();
employee1.applyBonus(2000);
employee2.applyBonus(2500);
System.out.println("\nAfter Bonus:");
employee1.printSalaryDetails();
employee2.printSalaryDetails();
System.out.println("\nGross Salary for Employee 1: " + employee1.calculateGrossSalary());
System.out.println("Gross Salary for Employee 2: " + employee2.calculateGrossSalary());
}
}