forked from ironhack-labs/lab-java-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntern.java
More file actions
29 lines (25 loc) · 850 Bytes
/
Intern.java
File metadata and controls
29 lines (25 loc) · 850 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
package Week2LabTest;
/**
* Represents an Intern, which is a specialized type of Employee.
* Enforces a maximum salary constraint.
*/
public class Intern extends Employee {
// Constant salary cap for all interns
public static final double MAX_SALARY = 20000;
public Intern(int id, String name, double salary, String department) {
super(id, name, 0, department); // initialize with safe salary
setSalary(salary); // apply validation
}
/**
* Overrides salary setter to enforce maximum salary rule.
*/
@Override
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
System.out.println("Salary exceeds intern limit. Setting to max: " + MAX_SALARY);
super.setSalary(MAX_SALARY);
} else {
super.setSalary(salary);
}
}
}