Repository navigation
Expand file tree
/
Copy pathAssignment1.java
More file actions
51 lines (42 loc) · 1.38 KB
/
Copy pathAssignment1.java
File metadata and controls
51 lines (42 loc) · 1.38 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
49
50
51
package Salary;
class Employee{
private String name;
private int id;
private double basicSalary;
private double hra; // house rent allowance
private double allowances;
private double grossSalary;
public Employee(String name, int id, double basicSalary, double hra, double allowances) {
this.name = name;
this.id = id;
this.basicSalary = basicSalary;
this.hra = hra;
this.allowances = allowances;
}
public void calculateGrossSalary() {
this.grossSalary = basicSalary + hra + allowances;
}
public void applyBonus(double bonus) {
this.grossSalary += bonus;
}
public void printSalaryDetails() {
System.out.println("Employee ID: " + id);
System.out.println("Name: " + name);
System.out.println("Basic Salary: " + basicSalary);
System.out.println("HRA: " + hra);
System.out.println("Allowances: " + allowances);
System.out.println("Gross Salary (after bonus, if any): " + grossSalary);
System.out.println("---------------------------------");
}
}
public class Salary {
public static void main(String[] args) {
Employee emp1 = new Employee("Anaan", 101, 30000, 5000, 2000);
Employee emp2 = new Employee("Burhaan", 102, 40000, 6000, 3000);
emp1.calculateGrossSalary();
emp1.printSalaryDetails();
emp2.calculateGrossSalary();
emp2.applyBonus(5000);
emp2.printSalaryDetails();
}
}