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

implemented getStatistic() method #1626

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

Conversation

nooobas
Copy link

@nooobas nooobas commented Feb 9, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Thank you for your hard work on this Pull Request! 😊 While your implementation of the getStatistic method in the WorkWithFile class is mostly correct and meets the core functionality requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Method Length and Single Responsibility Principle: The getStatistic method is currently too long and handles multiple responsibilities. It's important to break it down into smaller methods, each responsible for a single task, to improve readability and maintainability.

  2. Exception Handling: Using e.printStackTrace() is not ideal for production code. Instead, consider re-throwing a RuntimeException with a meaningful message or using a logging framework to handle exceptions more gracefully.

  3. Use of Constants: Hardcoded strings like "supply", "buy", and "result" should be declared as constants. This will enhance the readability and maintainability of your code.

These changes are crucial for ensuring that your code adheres to best practices and is easier to maintain in the future. Keep up the great work, and I look forward to seeing your improvements! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

Comment on lines 33 to 34
} catch (IOException e) {
e.printStackTrace();

Choose a reason for hiding this comment

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

Instead of using e.printStackTrace(), consider throwing a runtime exception or logging the error using a logging framework. This will provide more control over error handling and is generally more suitable for production environments.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Great job on your progress! 🎉 Your implementation of the WorkWithFile class is mostly correct, and you've made significant improvements to the code. Here are some key points to consider for future enhancements:

  1. Method Length and Single Responsibility Principle: The getStatistic method is currently handling multiple tasks, making it lengthy and complex. Breaking it down into smaller, more focused methods will improve both readability and maintainability.

  2. Exception Handling: While using RuntimeException is a step forward, consider adopting a more specific exception type or a logging framework for more robust error handling in production code.

  3. Use of Constants: The hardcoded strings "supply", "buy", and "result" should be declared as constants. This change will enhance the readability and maintainability of your code.

You've addressed some of these issues in your recent updates, which is commendable. Keep up the good work and continue refining your code. Remember, addressing these critical issues will help you avoid similar problems in the future and enhance your coding skills. Keep learning and improving! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines 10 to 31
public void getStatistic(String fromFileName, String toFileName) {
int supply = 0;
int buy = 0;

try (BufferedReader reader = new BufferedReader(new FileReader(fromFileName))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
String operation = parts[0].trim();
int amount = Integer.parseInt(parts[1].trim());

if ("supply".equalsIgnoreCase(operation)) {
supply += amount;
} else if ("buy".equalsIgnoreCase(operation)) {
buy += amount;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
writeToFile(supply, buy, toFileName);
}

Choose a reason for hiding this comment

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

The getStatistic method is too long and handles multiple responsibilities. Consider breaking it down into smaller methods, each responsible for a single task, to improve readability and maintainability.

Comment on lines 27 to 28
} catch (IOException e) {
throw new RuntimeException(e);

Choose a reason for hiding this comment

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

Using RuntimeException for exception handling is not ideal. Consider using a more specific exception type or a logging framework for better error handling.

Comment on lines 21 to 23
if ("supply".equalsIgnoreCase(operation)) {
supply += amount;
} else if ("buy".equalsIgnoreCase(operation)) {

Choose a reason for hiding this comment

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

The strings "supply" and "buy" are hardcoded. Consider declaring them as constants to enhance readability and maintainability.

try (BufferedWriter writer = new BufferedWriter(new FileWriter(toFileName))) {
writer.write("supply," + supply + "\n");
writer.write("buy," + buy + "\n");
writer.write("result," + result + "\n");

Choose a reason for hiding this comment

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

The string "result" is hardcoded. Consider declaring it as a constant to enhance readability and maintainability.

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.

2 participants