Skip to content

Commit

Permalink
Using two cycles for , StringBuilder , LocalDate, if , else if
Browse files Browse the repository at this point in the history
  • Loading branch information
DankevichMisha committed Nov 3, 2024
1 parent efce797 commit 14f7a20
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
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();
}
}

0 comments on commit 14f7a20

Please sign in to comment.