-
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
Showing
1 changed file
with
31 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,37 @@ | ||
package core.basesyntax; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.time.LocalDate; | ||
|
||
public class SalaryInfo { | ||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
StringBuilder result = new StringBuilder(); | ||
result.append("Report for period ").append(dateFrom).append(" - ").append(dateTo) | ||
.append(System.lineSeparator()); | ||
for (String name : names) { | ||
int userSalary = 0; | ||
for (String row : data) { | ||
String[] dataSplit = row.split(" "); | ||
String foundDate = dataSplit[0]; | ||
String foundName = dataSplit[1]; | ||
String foundHours = dataSplit[2]; | ||
String foundHourSalary = dataSplit[3]; | ||
if (name.equals(foundName) && isDateIncluded(dateFrom, dateTo, foundDate)) { | ||
userSalary += Integer.parseInt(foundHours) * Integer.parseInt(foundHourSalary); | ||
} | ||
} | ||
result.append(name).append(" - ").append(userSalary) | ||
.append(System.lineSeparator()); | ||
} | ||
return result.toString().trim(); | ||
} | ||
|
||
public boolean isDateIncluded(String dateFrom, String dateTo, String searchDate) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
LocalDate beginDate = LocalDate.parse(dateFrom, formatter); | ||
LocalDate endDate = LocalDate.parse(dateTo, formatter); | ||
LocalDate targetDate = LocalDate.parse(searchDate, formatter); | ||
return targetDate.isEqual(beginDate) || targetDate.isEqual(endDate) | ||
|| targetDate.isAfter(beginDate) && targetDate.isBefore(endDate); | ||
} | ||
} |