-
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.
- added implementation to the method getSalaryInfo(), class SalaryInfo - added parseDate() method to the class SalaryInfo
- Loading branch information
Dymchenko, Mykola
committed
Oct 23, 2024
1 parent
efce797
commit 0191af6
Showing
1 changed file
with
42 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,48 @@ | ||
package core.basesyntax; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class SalaryInfo { | ||
private static final int DATE_INDEX = 0; | ||
private static final int NAME_INDEX = 1; | ||
private static final int HOUR_INDEX = 2; | ||
private static final int SALARY_PER_HOUR_INDEX = 3; | ||
|
||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
|
||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
StringBuilder summaryReport = new StringBuilder("Report for period "); | ||
summaryReport | ||
.append(dateFrom) | ||
.append(" - ") | ||
.append(dateTo); | ||
LocalDate startDate = parseDate(dateFrom); | ||
LocalDate endDate = parseDate(dateTo); | ||
for (int i = 0; i < names.length; i++) { | ||
summaryReport.append("\n"); | ||
int salaryInfo = 0; | ||
for (int j = 0; j < data.length; j++) { | ||
String[] tempDataDetails = data[j].split(" "); | ||
LocalDate employeeDate = parseDate(tempDataDetails[DATE_INDEX]); | ||
if (names[i].equals(tempDataDetails[NAME_INDEX])) { | ||
if (employeeDate.isAfter(startDate) | ||
&& (employeeDate.isBefore(endDate) | ||
|| employeeDate.isEqual(endDate))) { | ||
salaryInfo += Integer.parseInt(tempDataDetails[HOUR_INDEX]) | ||
* Integer.parseInt(tempDataDetails[SALARY_PER_HOUR_INDEX]); | ||
} | ||
} | ||
} | ||
summaryReport | ||
.append(names[i]) | ||
.append(" - ") | ||
.append(salaryInfo); | ||
} | ||
return summaryReport.toString(); | ||
} | ||
|
||
private static LocalDate parseDate(String dateFrom) { | ||
return LocalDate.parse(dateFrom, FORMATTER); | ||
} | ||
} |