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

Solved the problem according to the principles of oop #1744

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

Conversation

pMukuta
Copy link

@pMukuta pMukuta commented Nov 14, 2024

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.


Hello! 😊 Your code is almost there, but there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Main Method Logic: The first loop in the Main class is missing the logic to populate the first half of the figures array with random figures. You should call figureSupplier.getRandomFigure() within this loop to assign a random figure to each element in the first half of the array. This is crucial for the functionality of your application.

  2. Direct Access to color Field: Ensure that accessing the color field directly in subclasses is intentional and consistent. If you have a getter method for color, consider using it for better encapsulation and consistency across your codebase.

These changes are important to ensure your application functions correctly and adheres to good coding practices. Once you've made these adjustments, feel free to resubmit your pull request. Keep up the great work, and I'm looking 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 18 to 19
System.out.println("Figure: circle, area: " + calculateArea() + " sq. units, radius: "
+ radius + " units, color: " + color);

Choose a reason for hiding this comment

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

Ensure that accessing the color field directly is intentional and consistent with how other subclasses of Figure handle this field. If you have a getter method for color, consider using it for consistency and encapsulation.

FigureSupplier figureSupplier = new FigureSupplier();
Figure[] figures = new Figure[6];

for (int i = 0; i < figures.length / 2; i++) {

Choose a reason for hiding this comment

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

The first loop is missing the logic to populate the first half of the figures array with random figures. You should call figureSupplier.getRandomFigure() within this loop to assign a random figure to each element in the first half of the array.

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 addressing the previous issues in your code! 🎉 Your implementation is well-structured, and the logic in the Main class is correctly set up to populate the figures array with both random and default figures.

Here are a few points to consider for further improvement:

  • Output Formatting: Ensure spaces are correctly placed in the draw method's output string for the Square and Rectangle classes. This will enhance readability.

  • Encapsulation: Use the getColor() method instead of directly accessing the color field in your subclasses. This aligns with good encapsulation practices.

  • Magic Numbers: Consider defining a constant for the number of figure types to improve code readability and maintainability.

These adjustments will not only make your code cleaner but also enhance its maintainability. Keep up the good work, and continue learning from these experiences! 🚀

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

private final Random random = new Random();

public Figure getRandomFigure() {
int figureType = random.nextInt(5);

Choose a reason for hiding this comment

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

Consider defining a constant for the number of figure types (5) to avoid using magic numbers. This will make your code more readable and easier to maintain. For example, you could define private static final int FIGURE_TYPES_COUNT = 5; and use it here.

public void draw() {
System.out.println("Shape: isosceles trapezoid, area: " + calculateArea()
+ " square units, first base: " + base1 + " units, second base: " + base2
+ " units, height: " + height + " units, color: " + color);

Choose a reason for hiding this comment

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

Consider using getColor() instead of accessing the color field directly for consistency and better encapsulation. This aligns with the practice of using getter methods to access private fields.

Comment on lines +20 to +21
System.out.println("Shape: rectangle, area: " + calculateArea() + "square units width: "
+ width + "height units: " + height + "color units: " + getColor());

Choose a reason for hiding this comment

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

There are missing spaces in the output string of the draw method. Consider adding spaces after 'square units', 'width:', and 'height:' for better readability. The corrected string should look like: "Shape: rectangle, area: " + calculateArea() + " square units, width: " + width + " units, height: " + height + " units, color: " + getColor().

Comment on lines +18 to +19
System.out.println("Figure: square, area: " + calculateArea() + "square units, side: "
+ side + " color, units" + getColor());

Choose a reason for hiding this comment

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

There are missing spaces in the output string of the draw method. Consider adding spaces after 'square units,' and before 'color' for better readability. The corrected string should look like: "Figure: square, area: " + calculateArea() + " square units, side: " + side + " units, color: " + getColor().

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