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

first commit #1358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions src/main/java/core/basesyntax/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package core.basesyntax;

public class Main {
public static void main(String[] args) {
String[] names = {
"John",
"Andrew",
"Kate"};

String[] data = {
"26.04.2019 John 4 50",
"05.04.2019 Andrew 3 200",
"10.04.2019 John 7 100",
"22.04.2019 Kate 9 100",
"25.06.2019 John 11 50",
"26.04.2019 Andrew 3 150",
"13.02.2019 John 7 100",
"15.04.2019 Kate 9 100"};

String dateFrom = "15.04.2019";
String dateTo = "31.04.2019";

String raport = SalaryInfo.getSalaryInfo(names, data, dateFrom, dateTo);

Choose a reason for hiding this comment

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

The variable name raport seems to be a typo. It should be report to match the standard English spelling and improve code readability.


System.out.println(raport);

Choose a reason for hiding this comment

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

Ensure that the variable name raport is corrected to report here as well, to maintain consistency after the change.

}
}
46 changes: 44 additions & 2 deletions src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
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;
public static String getSalaryInfo(
String[] names,
String[] data,
String dateFrom,
String dateTo) {

StringBuilder stringBuilder = new StringBuilder();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
LocalDate from = LocalDate.parse(dateFrom, formatter);
LocalDate to = LocalDate.parse(dateTo, formatter);

int[] result = new int[names.length];//зберігає результат

for (String record : data) {

String[] parts = record.split(" ");
LocalDate workDate = LocalDate.parse(parts[0], formatter);
String nameOfRecord = parts[1];
int workHour = Integer.parseInt(parts[2]);
int salaryPerHour = Integer.parseInt(parts[3]);

if (workDate.isAfter(from) && workDate.isBefore(to)
|| workDate.isEqual(from) || workDate.isEqual(to)) {
Comment on lines +28 to +29

Choose a reason for hiding this comment

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

The condition for checking if workDate is within the range might be misleading. Ensure that the logic correctly includes both from and to dates as intended. The current condition workDate.isAfter(from) && workDate.isBefore(to) || workDate.isEqual(from) || workDate.isEqual(to) should work, but double-check if it aligns with the task requirements for inclusivity.

for (int i = 0; i < result.length; i++) {
if (names[i].equals(nameOfRecord)) {
result[i] += workHour * salaryPerHour;
}
}
}
}

stringBuilder
.append("Report for period " + dateFrom + " - " + dateTo)
.append(System.lineSeparator());
for (int i = 0; i < names.length; i++) {
stringBuilder
.append(names[i]).append(" - ")
.append(result[i])
.append(System.lineSeparator());
}
return stringBuilder.toString().trim();
}
}
Loading