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 geometric shapes generator task #1755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SIPervii
Copy link

@SIPervii SIPervii commented Dec 2, 2024

Реализовал задачу генерации геометрических фигур. Исправил замечания AI.

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.


Your code implementation is quite solid and meets the task requirements, but there are a few areas for improvement that can enhance the readability and maintainability of your code. Here are some key points to consider:

  • Accessing Protected Fields: Ensure that the color field in the Circle class is accessed correctly in the draw() method. Since it's protected in the Figure class, it should be directly accessible in Circle.

  • Magic Numbers: In the FigureSupplier class, replace magic numbers like 5 in randomGenerator.nextInt(5) with named constants for better readability.

  • Method Naming: Consider renaming the getColorSupplier() method to getRandomColor() to better reflect its functionality.

  • Code Readability: Avoid passing expressions directly into constructors. Assign the results to variables first to improve code readability.

  • Output Formatting: Ensure proper spacing in System.out.println() statements, especially around the color, width, and height outputs, to enhance readability.

These improvements are crucial for maintaining clean and understandable code. Keep up the good work, and continue refining your skills! 😊

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

@Override
public void draw() {
System.out.println("Figure: circle, area: " + getArea()
+ " radius: " + radius + " color " + color);

Choose a reason for hiding this comment

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

The color field is protected in the Figure class, which means it can be accessed directly in the Circle class. Ensure that the color field is correctly accessed in the draw() method. Currently, it seems like there might be an issue with how color is being used in the System.out.println() statement.

private static final Random randomGenerator = new Random();
private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier();

public Figure getRandomFigure() {

Choose a reason for hiding this comment

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

Consider renaming the method getColorSupplier() in the ColorSupplier class to getRandomColor() to better reflect its purpose, as per the task description.

private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier();

public Figure getRandomFigure() {
switch (randomGenerator.nextInt(5)) {

Choose a reason for hiding this comment

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

The number 5 used in randomGenerator.nextInt(5) is a magic number. Consider defining it as a constant, such as FIGURE_COUNT, to improve code readability and maintainability.

Comment on lines +12 to +13
return new Square(COLOR_SUPPLIER.getColorSupplier(),
randomGenerator.nextDouble() * 10 + 1);

Choose a reason for hiding this comment

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

Avoid passing expressions directly into constructors. Instead, assign the expression results to variables and pass those variables to the constructor. This improves code readability.

Comment on lines +15 to +17
return new Rectangle(COLOR_SUPPLIER.getColorSupplier(),
randomGenerator.nextDouble() * 10 + 1,
randomGenerator.nextDouble() * 10 + 1);

Choose a reason for hiding this comment

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

Avoid passing expressions directly into constructors. Instead, assign the expression results to variables and pass those variables to the constructor. This improves code readability.

Comment on lines +23 to +24
return new Circle(COLOR_SUPPLIER.getColorSupplier(),
randomGenerator.nextDouble() * 10 + 1);

Choose a reason for hiding this comment

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

Avoid passing expressions directly into constructors. Instead, assign the expression results to variables and pass those variables to the constructor. This improves code readability.

Comment on lines +26 to +29
return new IsoscelesTrapezoid(COLOR_SUPPLIER.getColorSupplier(),
randomGenerator.nextDouble() * 10 + 1,
randomGenerator.nextDouble() * 10 + 1,
randomGenerator.nextDouble() * 10 + 1);

Choose a reason for hiding this comment

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

Avoid passing expressions directly into constructors. Instead, assign the expression results to variables and pass those variables to the constructor. This improves code readability.

Comment on lines +20 to +21
System.out.println("Figure rectangle, area: " + getArea() + " width" + width
+ " ,height" + height + " color " + color);

Choose a reason for hiding this comment

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

There is a missing space after 'width' and before 'height' in the System.out.println() statement. Consider adding spaces to improve the readability of the output.

Comment on lines +20 to +21
System.out.println("Figure RightTriangle, area: " + getArea() + ", firstLeg "
+ firstLeg + ", secondLeg " + secondLeg + " color " + color);

Choose a reason for hiding this comment

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

There is a missing space before 'color' in the System.out.println() statement. Consider adding a space to improve the readability of the output.

@Override
public void draw() {
System.out.println("Figure: square, area: "
+ getArea() + " one side: " + side + " color:" + color);

Choose a reason for hiding this comment

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

There is a missing space after 'color:' in the System.out.println() statement. Consider adding a space to improve the readability of the output.

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.

3 participants