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

commit salaryInfo #1274

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

commit salaryInfo #1274

wants to merge 5 commits into from

Conversation

nplastun
Copy link

@nplastun nplastun commented May 3, 2024

No description provided.

Copy link

@MentorMA MentorMA left a comment

Choose a reason for hiding this comment

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

You have big method, let`s divide it for private

Comment on lines 23 to 27
Date entryDate = dateFormat.parse(parts[0]);
if (name.equals(parts[1]) && !entryDate.before(fromDate)
&& !entryDate.after(toDate)) {
int hours = Integer.parseInt(parts[2]);
int rate = Integer.parseInt(parts[3]);
Copy link

Choose a reason for hiding this comment

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

Magic numbers

@nplastun nplastun requested a review from MentorMA May 3, 2024 17:04
Copy link

@sarakhmen sarakhmen left a comment

Choose a reason for hiding this comment

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

Let's slightly improve your solution ;)

Comment on lines 16 to 17
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
dateFormat.setLenient(false);

Choose a reason for hiding this comment

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

please move this local variable to the class fields

Comment on lines 22 to 28
List<String> reportLines = new ArrayList<>();
reportLines.add("Report for period " + dateFrom + " - " + dateTo);
for (String name : names) {
int earned = calculateEarnedSalary(name, data, fromDate, toDate, dateFormat);
reportLines.add(name + " - " + earned);
}
return String.join(System.lineSeparator(), reportLines);

Choose a reason for hiding this comment

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

let's use StringBuilder for these purposes

Copy link

@sarakhmen sarakhmen left a comment

Choose a reason for hiding this comment

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

Let's slightly improve your solution ;)

@nplastun nplastun requested a review from sarakhmen May 4, 2024 18:49
Comment on lines 17 to 18
Date fromDate = dateFormat.parse(dateFrom);
Date toDate = dateFormat.parse(dateTo);
Copy link

Choose a reason for hiding this comment

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

checklist issue, Date is outdated since Java 8, use LocalDate instead
image

public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
dateFormat.setLenient(false);
try {
Copy link

Choose a reason for hiding this comment

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

let's remove try-catch for clarity

Comment on lines 28 to 30
if (i < names.length - 1) {
reportLines.append(System.lineSeparator());
}
Copy link

Choose a reason for hiding this comment

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

instead of this check, just put lineSeparator at the beginning of each line (and remove it on line 22)

Comment on lines 8 to 11
static final int DATE_INDEX = 0;
static final int NAME_INDEX = 1;
static final int HOUR_INDEX = 2;
static final int RATE_INDEX = 3;
Copy link

Choose a reason for hiding this comment

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

don't forget private access modifier

@nplastun nplastun requested a review from okuzan May 6, 2024 07:31
Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

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

One more checklist issue

Comment on lines 13 to 14
LocalDate fromDate = LocalDate.parse(dateFrom, DateTimeFormatter.ofPattern("dd.MM.yyyy"));
LocalDate toDate = LocalDate.parse(dateTo, DateTimeFormatter.ofPattern("dd.MM.yyyy"));
Copy link

Choose a reason for hiding this comment

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

for (String entry : data) {
String[] parts = entry.split(" ");
LocalDate entryDate = LocalDate.parse(parts[DATE_INDEX],
DateTimeFormatter.ofPattern("dd.MM.yyyy"));
Copy link

Choose a reason for hiding this comment

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

here too

@nplastun nplastun requested a review from okuzan May 6, 2024 07:57
Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

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

Nice code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants