-
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.
- Loading branch information
1 parent
efce797
commit b988566
Showing
1 changed file
with
49 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,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); | ||
} | ||
} |