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 #1779

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

done #1779

wants to merge 2 commits into from

Conversation

xMaXD
Copy link

@xMaXD xMaXD commented Jan 8, 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.


Hello! 😊 You've done a great job implementing the classes and methods, and your code mostly meets the task requirements. However, there are a couple of critical issues that need to be addressed before we can approve the pull request:

  1. Returning null from a method: In the FigureSupplier class, the getRandomFigure() method returns null in the default case of the switch statement. This could lead to NullPointerException and is against best practices. Consider returning a default figure or handling this case differently.

  2. Magic numbers: The use of magic numbers, such as 5 in the random.nextInt(5) call, should be replaced with constants. This will improve the readability and maintainability of your code.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and I'm looking forward to seeing the 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.

ColorSupplier colorSupplier = new ColorSupplier();
Random random = new Random();
String color = colorSupplier.getRandomColor();
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 magic numbers and improve code readability.

random.nextDouble() * 10,
random.nextDouble() * 10,
random.nextDouble() * 10);
default: return null;

Choose a reason for hiding this comment

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

Returning null from a method is a bad practice. Instead of returning null in the default case, you could return a default figure or handle this case differently to avoid potential NullPointerException.

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.

Review Summary

Great job on implementing the various classes and interfaces! Your code is well-structured and demonstrates a solid understanding of object-oriented principles. Here are some key points from the review:

  • Magic Numbers: You've successfully replaced the magic number 5 with a constant FIGURE_COUNT in the FigureSupplier class, which enhances readability and maintainability. This is a good practice to follow in future projects as well.

  • Null Handling: The getRandomFigure() method in the FigureSupplier class no longer returns null, which is a significant improvement. Instead, it now returns a default figure using the getDefaultFigure() method, ensuring that your code is more robust and less prone to errors.

  • Class Implementations: All classes, such as Circle, Rectangle, Square, RightTriangle, and IsoscelesTrapezoid, are well-implemented. They correctly extend the Figure class and override necessary methods like getArea and draw. Your constructors are also well-defined, initializing attributes appropriately.

  • Interfaces and Abstract Classes: The Shape and Colored interfaces are correctly defined, and the Figure abstract class implements them properly. This setup allows for flexibility and scalability in your code.

  • Main Class: The Main class is effectively set up to demonstrate the functionality of your FigureSupplier class, showcasing your understanding of how to integrate and test your components.

Overall, your code meets the task requirements and constraints. While there are no critical issues, always strive to review and refine your code based on feedback. This will help you improve and learn from any mistakes. Keep up the great work, and continue to build on your skills! 🚀

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

ColorSupplier colorSupplier = new ColorSupplier();
Random random = new Random();
String color = colorSupplier.getRandomColor();
final 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 replacing the magic number 5 with a named constant to improve readability and maintainability. For example, you could define a constant private static final int NUMBER_OF_FIGURE_TYPES = 5; and use it here.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! Let’s improve your solution ;)

Comment on lines +22 to +23


Choose a reason for hiding this comment

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

Suggested change

Leave only one empty line at the end of the file (check it everywhere)

import java.util.Random;

public class ColorSupplier {
private static final String[] COLORS = {"Red", "Green", "Blue", "Yellow", "Black", "White"};

Choose a reason for hiding this comment

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

Let’s create separate enum class Color

private static final String[] COLORS = {"Red", "Green", "Blue", "Yellow", "Black", "White"};

public String getRandomColor() {
Random random = new Random();

Choose a reason for hiding this comment

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

Make Random private final class level variable

Comment on lines +3 to +6
public interface Colored {
String getColor();
}

Choose a reason for hiding this comment

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

remove this interface Color is state (not behavior)

Comment on lines +3 to +5
public abstract class Figure implements Shape, Colored {
private String color;

Choose a reason for hiding this comment

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

Suggested change
public abstract class Figure implements Shape, Colored {
private String color;
public abstract class Figure {
private Color color;

Comment on lines +7 to +8
ColorSupplier colorSupplier = new ColorSupplier();
Random random = new Random();

Choose a reason for hiding this comment

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

should be class level variable

ColorSupplier colorSupplier = new ColorSupplier();
Random random = new Random();
String color = colorSupplier.getRandomColor();
final 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.

use constant


switch (figureType) {
case 0: return new Square(color,
random.nextDouble() * 10);

Choose a reason for hiding this comment

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

the same. make 10 constant and reuse it

}

public Figure getDefaultFigure() {
return new Circle("White", 10);

Choose a reason for hiding this comment

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

use constants

Comment on lines +4 to +6
double getArea();

void draw();

Choose a reason for hiding this comment

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

create interfaces AreaCalculator with method getArea() and Drawable with draw()

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