-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.java
51 lines (43 loc) · 1.22 KB
/
worker.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 Worker {
String name;
double basic;
public Worker(String name, double basic) {
this.name = name;
this.basic = basic;
}
public void display() {
System.out.println("Worker Name: " + name);
System.out.println("Basic Pay: " + basic);
}
}
class Wages extends Worker {
double hrs;
double rate;
double wage;
public Wages(String name, double basic, double hrs, double rate) {
super(name, basic);
this.hrs = hrs;
this.rate = rate;
}
public double overtime() {
if (hrs > 40) {
return (hrs - 40) * rate;
}
return 0;
}
public void display() {
super.display();
double overtimeAmount = overtime();
wage = basic + overtimeAmount;
System.out.println("Hours Worked: " + hrs);
System.out.println("Rate Per Hour: " + rate);
System.out.println("Overtime Amount: " + overtimeAmount);
System.out.println("Monthly Wage: " + wage);
}
}
public class Main {
public static void main(String[] args) {
Wages wages = new Wages("John Doe", 2000.0, 45.0, 20.0);
wages.display();
}
}