Skip to content

Commit

Permalink
task done
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroW1zard committed Apr 12, 2024
1 parent efce797 commit f58cdf8
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package core.basesyntax;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class SalaryInfo {
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");

public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
LocalDate salaryDateFrom = LocalDate.parse(dateFrom, formatter);
LocalDate salaryDateTo = LocalDate.parse(dateTo, formatter);

int johnSalary = 0;
int andrewSalary = 0;
int kateSalary = 0;

for (int i = 0; i < data.length; i++) {
String[] tempData = data[i].split(" ");
LocalDate currentDate = LocalDate.parse(tempData[0], formatter);

if (currentDate.isAfter(salaryDateFrom.minusDays(1))
&& currentDate.isBefore(salaryDateTo.plusDays(1))) {
String name = tempData[1];
int hours = Integer.parseInt(tempData[2]);
int incomePerHour = Integer.parseInt(tempData[3]);

switch (name) {
case "John" -> johnSalary += hours * incomePerHour;
case "Andrew" -> andrewSalary += hours * incomePerHour;
case "Kate" -> kateSalary += hours * incomePerHour;
default -> {
continue;
}
}
}
}
String report = "Report for period " + dateFrom + " - " + dateTo
+ "\n" + names[0] + " - " + johnSalary
+ "\n" + names[1] + " - " + andrewSalary
+ "\n" + names[2] + " - " + kateSalary;

return report;
}
}

0 comments on commit f58cdf8

Please sign in to comment.