-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
first commit #1358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
|
||
System.out.println(raport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the variable name |
||
} | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition for checking if |
||
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(); | ||
} | ||
} |
There was a problem hiding this comment.
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 bereport
to match the standard English spelling and improve code readability.