-
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.
Using two cycles for , StringBuilder , LocalDate, if , else if
- Loading branch information
1 parent
efce797
commit 14f7a20
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.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class SalaryInfo { | ||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
StringBuilder salaryInfo = new StringBuilder(); | ||
LocalDate startDate = LocalDate.parse(dateFrom); | ||
LocalDate endDate = LocalDate.parse(dateTo); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); | ||
salaryInfo.append("Report for period "); | ||
salaryInfo.append(dateFrom); | ||
salaryInfo.append(" - "); | ||
salaryInfo.append(dateTo); | ||
for (String name : names) { | ||
int salary = 0; | ||
for (String datum : data) { | ||
String[] lines = datum.split(" "); | ||
LocalDate date = LocalDate.parse(lines[0]); | ||
String nameUser = lines[1]; | ||
if (date.isAfter(startDate) && date.isBefore(endDate) | ||
&& name.equals(nameUser)) { | ||
salary += Integer.parseInt(lines[2]) * Integer.parseInt(lines[3]); | ||
} else if (date.isEqual(startDate) && name.equals(nameUser) | ||
|| date.isEqual(endDate) && name.equals(nameUser)) { | ||
salary += Integer.parseInt(lines[2]) * Integer.parseInt(lines[3]); | ||
} | ||
} | ||
salaryInfo.append(System.lineSeparator()); | ||
salaryInfo.append(name); | ||
salaryInfo.append(" - "); | ||
salaryInfo.append(salary); | ||
} | ||
return salaryInfo.toString(); | ||
} | ||
} |