-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee_salary.java
51 lines (39 loc) · 1.15 KB
/
Employee_salary.java
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
class Employee {
protected double baseSalary;
public Employee(double baseSalary) {
this.baseSalary = baseSalary;
}
public double calculateSalary() {
return baseSalary;
}
}
class Manager extends Employee {
private double bonus;
public Manager(double baseSalary, double bonus) {
super(baseSalary);
this.bonus = bonus;
}
@Override
public double calculateSalary() {
return baseSalary + bonus;
}
}
class Programmer extends Employee {
private double overtimePay;
public Programmer(double baseSalary, double overtimePay) {
super(baseSalary);
this.overtimePay = overtimePay;
}
@Override
public double calculateSalary() {
return baseSalary + overtimePay;
}
}
class Main {
public static void main(String[] args) {
Employee manager = new Manager(50000, 10000);
Employee programmer = new Programmer(40000, 1000);
System.out.println("Manager Salary: " + manager.calculateSalary());
System.out.println("Programmer Salary: " + programmer.calculateSalary());
}
}