Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented method getSalaryInfo #1387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
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");
private static final int DATE = 0;
private static final int NAME = 1;
private static final int WORK_HOURS = 2;
private static final int SALARY_PER_HOUR = 3;

public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
LocalDate startDate = LocalDate.parse(dateFrom, FORMATTER);
LocalDate endDate = LocalDate.parse(dateTo, FORMATTER);
StringBuilder salaryAmount = new StringBuilder();

for (String name: names) {
int salary = 0;
for (String info: data) {
String[] information = info.split(" ");
LocalDate dateFormed = LocalDate.parse(information[DATE], FORMATTER);
if (!dateFormed.isAfter(endDate) && !dateFormed.isBefore(startDate)) {
if (name.equals(information[NAME])) {
salary += Integer.parseInt(information[WORK_HOURS])
* Integer.parseInt(information[SALARY_PER_HOUR]);
}
}
}
salaryAmount.append(System.lineSeparator()).append(name).append(" - ").append(salary);
}
return "Report for period " + dateFrom + " - " + dateTo + salaryAmount;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separator also should be a constant field

}
}
Loading