-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathIntern.java
More file actions
31 lines (28 loc) · 923 Bytes
/
Intern.java
File metadata and controls
31 lines (28 loc) · 923 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
public class Intern extends Employee {
// Salary limit constant
private static final double MAX_SALARY = 20000.0;
public Intern(String name, int id, double salary) {
super(name, id, salary);
// Validate salary on creation
if (salary > MAX_SALARY) {
throw new IllegalArgumentException("Intern salary cannot exceed " + MAX_SALARY);
}
}
// Override setter to validate on update
@Override
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
throw new IllegalArgumentException("Intern salary cannot exceed " + MAX_SALARY);
} else {
super.setSalary(salary);
}
}
@Override
public String toString() {
return "Intern{" +
"name='" + getName() + '\'' +
", id=" + getId() +
", salary=" + getSalary() +
'}';
}
}