-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
45 lines (37 loc) · 1.08 KB
/
Copy pathEmployee.java
File metadata and controls
45 lines (37 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
40
41
42
43
44
45
package java8.terminalOperation;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Employee {
private String name;
private String department;
private int salary;
public Employee(String name, String department, int salary) {
this.name = name;
this.department = department;
this.salary = salary;
}
public String getName() {
return name;
}
public String getDepartment() {
return department;
}
public int getSalary() {
return salary;
}
public Employee merge(Employee other) {
if (!name.equals(other.name)) {
throw new IllegalArgumentException("Cannot merge different employees: " + name + ", " + other.name);
}
if (!department.equals(other.department)) {
throw new IllegalArgumentException("Cannot merge employees from different departments: " + name);
}
return new Employee(name, department, salary + other.salary);
}
@Override
public String toString() {
return "Employee{" + "name='" + name + '\'' + ", department='" + department + '\'' + ", salary=" + salary + '}';
}
}