Repository navigation
Expand file tree
/
Copy pathEmployee.java
More file actions
82 lines (70 loc) · 2.09 KB
/
Copy pathEmployee.java
File metadata and controls
82 lines (70 loc) · 2.09 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public abstract class Employee {
String name;
int id;
int baseSalary;
public Employee(String name, int baseSalary, int id) {
this.name = name;
this.baseSalary = baseSalary;
this.id = id;
}
public Employee(String name, int id) {
this.name = name;
this.id = id;
this.baseSalary = 0;
}
public abstract double calculateSalary();
public void displayEmployeeInfo(){
System.out.println("Name: " + name + "\nID:" + id + "\nBase salary: " + baseSalary);
}
}
interface Payable{
public double getPaymentAmount();
}
class FullTimeEmployee extends Employee implements Payable{
double bonus = 1.2;
boolean healthInsurance = true;
public FullTimeEmployee(String name, int salary, int id) {
super(name, salary, id);
}
public double calculateSalary(){
return baseSalary*bonus;
}
public void displayEmployeeInfo(){
super.displayEmployeeInfo();
}
public double getPaymentAmount(){
return calculateSalary();
}
}
class ContractEmployee extends Employee implements Payable{
int hoursWorked;
int hourlyRate;
public ContractEmployee(String name, int id, int hourlyRate, int hoursWorked) {
super(name, id);
this.baseSalary = 0;
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
public double calculateSalary(){
return hoursWorked*hourlyRate;
}
public void displayEmployeeInfo(){
super.displayEmployeeInfo();
}
public double getPaymentAmount(){
return calculateSalary();
}
}
class EmployeeManager{
public static void main(String[] args) {
Employee[] employees = new Employee[10];
employees[0] = new FullTimeEmployee("Salma", 10000, 100);
employees[1] = new ContractEmployee("Atai", 100, 100, 12);
for (Employee employee : employees) {
if (employee != null) {
employee.displayEmployeeInfo();
System.out.println("Total Salary: " + employee.calculateSalary());
}
}
}
}