Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# jv-salary-info

Implement method `getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo)`. It should calculate the salary for employees. As input, you receive two arrays and two dates in String format.
Implement method `getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo)`.
It should calculate the salary for employees. As input, you receive two arrays and two dates in String format.
- Date represents limits that you should meet while calculating salary for employees (inclusively).
- The first array (`names`) contains the names of employees you should calculate salary for.
- The second array (`data`) contains info about their working hour during the particular day and income per hour.
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
package core.basesyntax;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class SalaryInfo {
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
StringBuilder namesData = new StringBuilder("Report for period "
+ dateFrom + " - " + dateTo)
.append(System.lineSeparator());
String europeanDatePattern = "dd.MM.yyyy";
DateTimeFormatter europeanDateFormatter = DateTimeFormatter
.ofPattern(europeanDatePattern);
LocalDate from = LocalDate.parse(dateFrom,europeanDateFormatter);
LocalDate to = LocalDate.parse(dateTo,europeanDateFormatter);
for (int i = 0; i < names.length; i++) {
int salary = 0;
for (String datas : data) {
String[] parts = datas.split(" ");
LocalDate date = LocalDate.parse(parts[0], europeanDateFormatter);
if (names[i].equals(parts[1])
&& !date.isBefore(from)
&& !date.isAfter(to)) {
salary += Integer.parseInt(parts[2]) * Integer.parseInt(parts[3]);
}

}

namesData.append(names[i])
.append(" - ")
.append(salary);

if (i < names.length - 1) {
namesData.append(System.lineSeparator());
}

}
return namesData.toString();
}
}
Loading