-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCompany.java
More file actions
68 lines (53 loc) · 1.46 KB
/
Company.java
File metadata and controls
68 lines (53 loc) · 1.46 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.ArrayList;
public class Company {
private String name;
private ArrayList<Employee> employees;
private int numberOfEmployees;
public Company(String name) {
this.name = name;
employees = new ArrayList<>();
}
public void addEmployee(Employee employee) {
employees.add(employee);
numberOfEmployees++;
}
public void print() {
System.out.println(name + " (" + numberOfEmployees + " Mitarbeiter)");
for (Employee e : employees) {
e.print();
}
}
public class Employee {
private int employeeId;
private Person person;
private int salary;
public Employee(int employeeId, Person person, int salary) {
this.employeeId = employeeId;
this.person = person;
this.salary = salary;
}
public int getEmployeeId() {
return employeeId;
}
public String getName() {
return person.getName();
}
public int getSalary() {
return salary;
}
public void setSalary(int salary)
throws SalaryDecreaseException, SalaryIncreaseTooHighException {
if (salary < this.salary) {
throw new SalaryDecreaseException();
}
double increase = (double) (salary - this.salary) / this.salary;
if (increase > 0.1) {
throw new SalaryIncreaseTooHighException();
}
this.salary = salary;
}
public void print() {
System.out.println(employeeId + " - " + getName() + " - " + salary + " Euro");
}
}
}