From 0c939828bd61e21142207e1fc958974bfc0d103e Mon Sep 17 00:00:00 2001 From: Wojtek Date: Sat, 14 Dec 2024 19:30:01 +0100 Subject: [PATCH] Final commit. --- src/main/java/core/basesyntax/SalaryInfo.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/core/basesyntax/SalaryInfo.java b/src/main/java/core/basesyntax/SalaryInfo.java index fcc575fb8..a70398007 100644 --- a/src/main/java/core/basesyntax/SalaryInfo.java +++ b/src/main/java/core/basesyntax/SalaryInfo.java @@ -10,7 +10,8 @@ public class SalaryInfo { private static final int HOURS = 2; private static final int INCOME = 3; private static final int DAY = 1; - private static final String DATE_FORMAT = "dd.MM.yyyy"; + private static final String DASH = " - "; + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy"); public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { LocalDate dateFromDateFormat = changeDateFormat(dateFrom); @@ -29,23 +30,20 @@ && changeDateFormat(dataInfo[DATE]).isBefore(dateToDateFormat.plusDays(DAY))) { } } } - - StringBuilder stringBuilder = new StringBuilder("Report for period " + dateFrom + StringBuilder result = new StringBuilder("Report for period " + dateFrom + " - " + dateTo + System.lineSeparator()); for (int i = 0; i < names.length; i++) { if (i != names.length - 1) { - stringBuilder.append(names[i]).append(" - ").append(salary[i]) + result.append(names[i]).append(DASH).append(salary[i]) .append(System.lineSeparator()); } else { - stringBuilder.append(names[i]).append(" - ").append(salary[i]); + result.append(names[i]).append(DASH).append(salary[i]); } } - - return stringBuilder.toString(); + return result.toString(); } public LocalDate changeDateFormat(String stringDate) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); - return LocalDate.parse(stringDate, formatter); + return LocalDate.parse(stringDate, FORMATTER); } }