Repository navigation
Expand file tree
/
Copy pathTask5.java
More file actions
74 lines (56 loc) · 1.78 KB
/
Copy pathTask5.java
File metadata and controls
74 lines (56 loc) · 1.78 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
abstract class Employee {
String name;
int id;
public Employee(String name, int id) {
this.name = name;
this.id = id;
}
public abstract double calculateSalary();
}
interface TaxPayer {
void payTax();
}
class FullTimeEmployee extends Employee implements TaxPayer {
double monthlySalary;
public FullTimeEmployee(String name, int id, double monthlySalary) {
super(name, id);
this.monthlySalary = monthlySalary;
}
@Override
public double calculateSalary() {
return monthlySalary;
}
@Override
public void payTax() {
double tax = 0.2 * calculateSalary();
System.out.println(name + " (Full-Time) paid tax: $" + tax);
}
}
class PartTimeEmployee extends Employee implements TaxPayer {
double hourlyRate;
int hoursWorked;
public PartTimeEmployee(String name, int id, double hourlyRate, int hoursWorked) {
super(name, id);
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
@Override
public double calculateSalary() {
return hourlyRate * hoursWorked;
}
@Override
public void payTax() {
double tax = 0.1 * calculateSalary();
System.out.println(name + " (Part-Time) paid tax: $" + tax);
}
}
public class Task5 {
public static void main(String[] args) {
FullTimeEmployee fte = new FullTimeEmployee("Wafa Ali", 132, 5000.0);
PartTimeEmployee pte = new PartTimeEmployee("Nickel", 136, 20.0, 80);
System.out.println(fte.name + "'s salary: $" + fte.calculateSalary());
fte.payTax();
System.out.println(pte.name + "'s salary: $" + pte.calculateSalary());
pte.payTax();
}
}