-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4 Worker.java
More file actions
43 lines (36 loc) · 909 Bytes
/
Q4 Worker.java
File metadata and controls
43 lines (36 loc) · 909 Bytes
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
class Worker {
String name;
double basic;
Worker(String name, double basic) {
this.name = name;
this.basic = basic;
}
void display() {
System.out.println("Name: " + name);
System.out.println("Basic Pay: $" + basic);
}
}
class Wages extends Worker {
double hrs;
double rate;
double wage;
Wages(String name, double basic, double hrs, double rate) {
super(name, basic);
this.hrs = hrs;
this.rate = rate;
calculateWage();
}
double overtime() {
return (hrs > 40) ? (hrs - 40) * rate * 1.5 : 0;
}
void calculateWage() {
wage = basic + overtime();
}
@Override
void display() {
super.display();
System.out.println("Hours Worked: " + hrs);
System.out.println("Hourly Rate: $" + rate);
System.out.println("Wage: $" + wage);
}
}