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

done #1750

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

done #1750

wants to merge 1 commit into from

Conversation

rafael60193
Copy link

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.


Great job on implementing the AreaCalculator and Draw interfaces, as well as the various figure classes! 🎉 Your code structure is well-organized, and you've effectively utilized interfaces and enums to ensure consistency across implementations. Here are a few key points to consider for improvement:

  1. Magic Numbers: Replace magic numbers with named constants to enhance code readability and maintainability. This will make your code easier to understand and modify in the future.

  2. FigureSupplier Instance: Create a single instance of FigureSupplier outside the loop in the Main class to avoid unnecessary instantiation. This will improve performance and readability.

  3. Random Figure Generation: Recalculate the index inside the getRandomFigure method to ensure a different figure type can be returned each time, providing more variety in generated figures.

  4. Abstract Methods: Consider making the calculateArea and draw methods abstract in the Figure class to enforce that subclasses provide meaningful implementations.

  5. Color Consistency: Return a Color type instead of a String from the getRandomColor method to maintain type consistency across your application.

These improvements will help you write cleaner, more efficient code. Keep up the great work, and continue learning from these experiences! 🚀

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

Comment on lines +8 to +10
public String getRandomColor() {
Color[] color = Color.values();
return color[random.nextInt(color.length)].name();

Choose a reason for hiding this comment

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

Consider returning a Color type instead of a String from the getRandomColor method. This will ensure type consistency across the application when dealing with colors.

Comment on lines +19 to +20
public double calculateArea() {
return 0;

Choose a reason for hiding this comment

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

The calculateArea method returns 0, which might not be meaningful for a base class. Consider making this method abstract to enforce subclasses to provide their own implementation.

Comment on lines +24 to +25
public void draw() {
System.out.println("message");

Choose a reason for hiding this comment

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

The draw method currently prints a generic message. Consider making this method abstract or providing a more meaningful default implementation.

private int maxBound = 5;
private ColorSupplier colorSupplier = new ColorSupplier();
private Random random = new Random();
private int index = random.nextInt(maxBound);

Choose a reason for hiding this comment

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

The index is calculated once during the instantiation of FigureSupplier. This means getRandomFigure will always return the same type of figure. Consider recalculating index inside the getRandomFigure method to ensure a different figure type can be returned each time.

Comment on lines +6 to +8
private int defaultSize = 10;
private int maxSize = 50;
private int maxBound = 5;

Choose a reason for hiding this comment

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

Avoid using magic numbers directly in the code. Define defaultSize, maxSize, maxBound, and any other magic numbers as constants to improve code readability and maintainability.

Comment on lines +20 to +30
return new Circle(randomSize(), colorSupplier.getRandomColor());
case 1:
return new Square(randomSize(), colorSupplier.getRandomColor());
case 2:
return new Rectangle(colorSupplier.getRandomColor(), randomSize(), randomSize());
case 3:
return new RightTriangle(randomSize(),
randomSize(), colorSupplier.getRandomColor());
default:
return new IsoscelesTrapezoid(randomSize(),
randomSize(), randomSize(), colorSupplier.getRandomColor());

Choose a reason for hiding this comment

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

When creating figures, avoid passing expressions directly into constructors. Instead, assign the results of expressions to variables and pass those variables to constructors. This improves code readability.

Comment on lines +11 to +14
figures[i] = new FigureSupplier().getRandomFigure();
figures[i].draw();
} else {
figures[i] = new FigureSupplier().getDefaultFigure();

Choose a reason for hiding this comment

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

Consider creating a single instance of FigureSupplier outside the loop to avoid unnecessary instantiation within each iteration. This will improve performance and readability.

@Override
public void draw() {
String firstPart = "Figure: square, area: " + calculateArea() + " sq. units, side: ";
String secondPart = side + " unists, color: " + getColor();

Choose a reason for hiding this comment

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

There is a typo in the word 'unists'. It should be 'units'.

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