Kursach1 is done#7
Conversation
| public void setSalary(float salary) { | ||
| this.salary = salary; | ||
| } | ||
| } |
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| EmployeeBook that = (EmployeeBook) o; | ||
| return Arrays.equals(employees, that.employees); | ||
| } |
There was a problem hiding this comment.
Книга у нас одна. Не думаю, что её будем с чем-то сравнивать.
| StringBuilder print = new StringBuilder("Employees from department " + department + System.lineSeparator()); | ||
| for (Employee employee : employees) { | ||
| if (employee != null && department == employee.getDepartment()) { | ||
| print.append(employee.getName()).append(" ").append(" ").append(employee.getSalary()).append(" ").append(employee.getId()).append(System.lineSeparator()); |
There was a problem hiding this comment.
Вот чтобы это полотенце текста не писать, нужно реализовывать в Employee метод toString.
Тогда можно было бы написать append(employee) и всё.
| } | ||
|
|
||
| public void changeEmployeeSalaryByName(String name, int newSalary) { | ||
| for (int i = 0; i < employees.length - 1; i++) |
There was a problem hiding this comment.
Не могу найти где, вроде все работает
| } | ||
| } | ||
| public void changeEmployeeDepartmentByName(String name, int newDepartment) { | ||
| for (int i = 0; i < employees.length - 1; i++) |
| } | ||
|
|
||
| public float departmentSalarySpendings(int department) { | ||
| float b = 0; |
There was a problem hiding this comment.
Плохое имя.
totalSum или хотя бы result, если ничего в голову не лезет, но точно не b
| float b = 0; | ||
| for (Employee employee : employees) { | ||
| if (employee != null && employee.getDepartment() == department) { | ||
| b = b + employee.getSalary(); |
| public float departmentAverageSalarySpendings (int department) { | ||
| float b = 0; | ||
| float c = 0; | ||
| for (Employee employee : employees) { | ||
| if (employee != null &&employee.getDepartment() == department) { | ||
| b = b + employee.getSalary(); | ||
| c++; | ||
| } | ||
| } | ||
| return b/c; | ||
| } |
There was a problem hiding this comment.
То же, что было сказано о прошлом методе.
| public void changeDepartmentSalaries(float incr, int department) { | ||
| float a; | ||
| for (Employee employee : employees) { | ||
| if (employee != null && employee.getDepartment() == department) { | ||
| a = employee.getSalary() + employee.getSalary() * (incr / 100); | ||
| employee.setSalary(a); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
То же, что было сказано о прошлом методе по работе с зп.
| public String salaryToValueLess(float value) { | ||
| StringBuilder a = new StringBuilder(); | ||
| for (Employee employee : employees) { | ||
| if (employee != null &&value > employee.getSalary()) { | ||
| a.append(employee.getName()).append(" ").append(employee.getSalary()).append(employee.getId()).append(System.lineSeparator()); | ||
| } | ||
| } | ||
| return a.toString(); | ||
| } | ||
| public String salaryToValueMoreOrEqual(float value) { | ||
| StringBuilder a = new StringBuilder(); | ||
| for (Employee employee : employees) { | ||
| if (employee != null && value <= employee.getSalary()) { | ||
| a.append(employee.getName()).append(" ").append(employee.getSalary()).append(employee.getId()).append(System.lineSeparator()); | ||
| } | ||
| } | ||
| return a.toString(); | ||
| } |
There was a problem hiding this comment.
Здесь, как я помню, тоже не строку нужно возвращать.
Если я правильно помню, нужно было печатать тех, кто ниже по зп.
| public void setSalary(float salary) { | ||
| this.salary = salary; | ||
| } | ||
| } |
|
|
||
|
|
||
|
|
||
| public int counter; |
There was a problem hiding this comment.
Поле поменяно на Privatе оно необходимо для ошибки если работник не найден
There was a problem hiding this comment.
А еще оно выполняет подсчет числа работников
| } | ||
|
|
||
| public void changeEmployeeSalaryByName(String name, int newSalary) { | ||
| int counter1 = 0; |
| counter1++; | ||
| } | ||
| } | ||
| if (counter1 > 0) { |
There was a problem hiding this comment.
Если найдено несколько работников с одним ФИО, то это проблема.
Это не должно так работать.
| employees[i].setSalary(newSalary); | ||
| return; |
There was a problem hiding this comment.
Этот код должен быть в первом цикле, где происходит counter1++;
| employees[i].setSalary(newSalary); | ||
| return; | ||
| } | ||
| } else { |
| for (int i = 0; i < employees.length - 1; i++) { | ||
| if (employees[i] != null && minSalary == employees[i].getSalary() && employees[i].getDepartment() == department) { | ||
| minSalaryDepartmentName = employees[i]; | ||
| } | ||
|
|
||
| } |
| for (int i = 0; i < employees.length - 1; i++) { | ||
| if (employees[i] != null && minSalary > employees[i].getSalary() && employees[i].getDepartment() == department) { | ||
| minSalary = employees[i].getSalary(); | ||
|
|
There was a problem hiding this comment.
minSalaryDepartmentName = employees[i];
| public Employee findMaxSalaryDepartment(int department) { | ||
| Employee maxSalaryDepartmentName = null; | ||
| float maxSalary = 0; | ||
| for (Employee employee : employees) { | ||
| if (employee != null && maxSalary < employee.getSalary() && employee.getDepartment() == department) { | ||
| maxSalary = employee.getSalary(); | ||
|
|
||
| } | ||
| } | ||
| for (Employee employee : employees) { | ||
| if (employee != null && maxSalary == employee.getSalary() && employee.getDepartment() == department) { | ||
| maxSalaryDepartmentName = employee; | ||
| } | ||
|
|
||
| } | ||
| return maxSalaryDepartmentName; | ||
| } |
There was a problem hiding this comment.
Те же комментарии, что были к прошлому методу.
| } | ||
| public float calculateDepartmentAverageSalarySpendings (int department) { | ||
| float totalSalary = 0; | ||
| float counter = 0; |
There was a problem hiding this comment.
Почему этот счётчик float? У нас может быть 1,5 землекопа?
| return totalSalary/counter; | ||
| } | ||
| public void changeDepartmentSalaries(int percent, int department) { | ||
| float newSalary; |
There was a problem hiding this comment.
Эта переменная вне цикла не имеет смысла.
Её можно создавать там же, где идёт инициализация.
| public String toString() { | ||
| return name + ' ' + department + | ||
| " " + salary + | ||
| " " + id + System.lineSeparator(); | ||
| } |
There was a problem hiding this comment.
Совсем не понимаю, почему id выводится последним.
И почему один из пробелов в виде char?
| for (Employee employee : employees) { | ||
| if (employee != null && department == employee.getDepartment()) { | ||
| print.append(employee); | ||
| System.out.println(print); |
There was a problem hiding this comment.
Печать должна быть вынесена из цикла.
У тебя получается, что в консоль выводится каждый раз весь список сотрудников.
Т.е. добавила нового сотрудника в билдер, затем напечатала всё, что уже есть в билдере, затем добавила, затем снова напечатала весь билдер.
Печатать билдер нужно после цикла.
| System.out.println("Not found Employee"); | ||
| } | ||
|
|
||
| public void deleteEmployeeName(String name) { |
| StringBuilder print = new StringBuilder("Employees " + System.lineSeparator()); | ||
| for (Employee employee : employees) { | ||
| if (employee != null) { | ||
| print.append(employee); |
There was a problem hiding this comment.
Нужен ещё append '\n', так как сейчас они аппендятся в строку.
| float newSalary; | ||
| if (employee != null && employee.getDepartment() == department) { | ||
| newSalary = employee.getSalary() + employee.getSalary() * multiplier; |
There was a problem hiding this comment.
Зачем разделять объявление и инициализацию? Объедини строку с объявлением и инициализацией переменной в одну.
| public void printEmployeesWithSalaryToValueLess(float value) { | ||
| StringBuilder employeeLessToValue = new StringBuilder(); | ||
| for (Employee employee : employees) { | ||
| if (employee != null && value > employee.getSalary()) { | ||
| employeeLessToValue.append(employee); | ||
| } | ||
| } | ||
| System.out.println(employeeLessToValue); | ||
| } | ||
| public void printEmployeesWithSalaryToValueMoreOrEqual(float value) { | ||
| StringBuilder employeeMoreToValue = new StringBuilder(); | ||
| for (Employee employee : employees) { | ||
| if (employee != null && value <= employee.getSalary()) { | ||
| employeeMoreToValue.append(employee); | ||
| } | ||
| } | ||
| System.out.println(employeeMoreToValue); | ||
| } |
There was a problem hiding this comment.
Нет append новой линии между работниками.
При печати всё соберется в одну строку.
No description provided.