Skip to content

Commit

Permalink
Initial commit for hw-solution
Browse files Browse the repository at this point in the history
  • Loading branch information
katrienkraska committed Oct 25, 2024
1 parent efce797 commit b988566
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
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;
int johnSalary = 0;
int andrewSalary = 0;
int kateSalary = 0;

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");

LocalDate startDate = LocalDate.parse(dateFrom, formatter);
LocalDate endDate = LocalDate.parse(dateTo, formatter);

for (String record : data) {
String[] parts = record.split(" ");
String dateStr = parts[0];
String name = parts[1];
int hours = Integer.parseInt(parts[2]);
int rate = Integer.parseInt(parts[3]);
LocalDate date = LocalDate.parse(dateStr, formatter);

if (date.isBefore(startDate) || date.isAfter(endDate)) {
continue;
}

boolean isEmployeeInList = false;
for (String employeeName : names) {
if (employeeName.equals(name)) {
isEmployeeInList = true;
break;
}
}
if (!isEmployeeInList) {
continue;
}

int salary = hours * rate;

if (name.equals("John")) {
johnSalary += salary;
} else if (name.equals("Andrew")) {
andrewSalary += salary;
} else if (name.equals("Kate")) {
kateSalary += salary;
}
}
return ("Report for period " + dateFrom + " - " + dateTo + "\n"
+ "John - " + johnSalary + "\n"
+ "Andrew - " + andrewSalary + "\n"
+ "Kate - " + kateSalary);
}
}

0 comments on commit b988566

Please sign in to comment.