-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efce797
commit 7fb39a1
Showing
1 changed file
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
package core.basesyntax; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class SalaryInfo { | ||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
LocalDate dateStart = LocalDate.parse(dateFrom, formatter); | ||
LocalDate dateEnd = LocalDate.parse(dateTo, formatter); | ||
StringBuilder salaryReport = new StringBuilder(); | ||
salaryReport.append("Report for period ").append(dateFrom).append(" - ") | ||
.append(dateTo).append(System.lineSeparator()); | ||
for (String name : names) { | ||
int salaryTotal = 0; | ||
for (String record : data) { | ||
String[] partOfRecord = record.split(" "); | ||
LocalDate workingDay = LocalDate.parse(partOfRecord[0], formatter); | ||
String employeeName = partOfRecord[1]; | ||
int workingHours = Integer.parseInt(partOfRecord[2]); | ||
int salaryPerHour = Integer.parseInt(partOfRecord[3]); | ||
if (employeeName.equals(name) && !workingDay.isBefore(dateStart) && !workingDay.isAfter(dateEnd)) { | ||
salaryTotal += workingHours * salaryPerHour; | ||
} | ||
} | ||
salaryReport.append(name).append(" - ").append(salaryTotal).append(System.lineSeparator()); | ||
} | ||
return salaryReport.toString(); | ||
} | ||
} |