-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 theCircle
class is accessed correctly in thedraw()
method. Since it's protected in theFigure
class, it should be directly accessible inCircle
. -
Magic Numbers: In the
FigureSupplier
class, replace magic numbers like5
inrandomGenerator.nextInt(5)
with named constants for better readability. -
Method Naming: Consider renaming the
getColorSupplier()
method togetRandomColor()
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 thecolor
,width
, andheight
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); |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
return new Square(COLOR_SUPPLIER.getColorSupplier(), | ||
randomGenerator.nextDouble() * 10 + 1); |
There was a problem hiding this comment.
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.
return new Rectangle(COLOR_SUPPLIER.getColorSupplier(), | ||
randomGenerator.nextDouble() * 10 + 1, | ||
randomGenerator.nextDouble() * 10 + 1); |
There was a problem hiding this comment.
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.
return new Circle(COLOR_SUPPLIER.getColorSupplier(), | ||
randomGenerator.nextDouble() * 10 + 1); |
There was a problem hiding this comment.
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.
return new IsoscelesTrapezoid(COLOR_SUPPLIER.getColorSupplier(), | ||
randomGenerator.nextDouble() * 10 + 1, | ||
randomGenerator.nextDouble() * 10 + 1, | ||
randomGenerator.nextDouble() * 10 + 1); |
There was a problem hiding this comment.
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.
System.out.println("Figure rectangle, area: " + getArea() + " width" + width | ||
+ " ,height" + height + " color " + color); |
There was a problem hiding this comment.
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.
System.out.println("Figure RightTriangle, area: " + getArea() + ", firstLeg " | ||
+ firstLeg + ", secondLeg " + secondLeg + " color " + color); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Реализовал задачу генерации геометрических фигур. Исправил замечания AI.