-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartTimeEmployee.java
More file actions
39 lines (36 loc) · 1.08 KB
/
Copy pathPartTimeEmployee.java
File metadata and controls
39 lines (36 loc) · 1.08 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
package Phase3_ObjectOrientation.EmployeeApp;
/**
* PartTimeEmployee - paid by the hour, capped at a monthly hour budget.
* <p>
*
* Records:
* - id : numeric id
* - name : staff name
* - hourlyRate : currency per hour
* - hoursLogged : hours worked this month
* <p>
*
* monthlyPay() = hourlyRate * hoursLogged
* <p>
*
* Implements Auditable but NOT Promotable - part-time staff in this model
* get raised by changing hourlyRate, not by a `promote(...)` call.
*/
public record PartTimeEmployee(
int id,
String name,
double hourlyRate,
double hoursLogged
) implements Employee, Auditable {
public PartTimeEmployee {
if (name == null || name.isBlank()) {
throw new IllegalArgumentException("name required");
}
if (hourlyRate < 0) throw new IllegalArgumentException("hourlyRate must be >= 0");
if (hoursLogged < 0) throw new IllegalArgumentException("hoursLogged must be >= 0");
}
@Override
public double monthlyPay() {
return hourlyRate * hoursLogged;
}
}