-
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
Done #1775
base: master
Are you sure you want to change the base?
Done #1775
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.
Thank you for your hard work on this project! While your code is well-structured and mostly meets the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Static Methods Usage: The use of static methods in
FigureSupplier
andColorSupplier
goes against the checklist's recommendations. It's important to create instances of these classes and call methods on those instances to adhere to best practices. -
Isosceles Trapezoid Area Calculation: The formula for calculating the area of an isosceles trapezoid is incorrect. It should be
((firstBase + secondBase) / 2) * height
. This is a critical issue as it affects the functionality of your code. -
Magic Numbers: The presence of magic numbers, such as
4
in theFigureSupplier
, should be replaced with named constants for better readability and maintainability. -
Inheritance Misuse: Extending
ColorSupplier
inFigureSupplier
is unnecessary and doesn't align with the task requirements. Consider using composition instead.
These issues are important to address to ensure your code is functional and maintainable. Once these changes are made, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you have any questions. 😊
✨ 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.
|
||
import java.util.Random; | ||
|
||
public class FigureSupplier extends ColorSupplier { |
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 extending ColorSupplier
as it doesn't provide any additional benefit in this context. Consider using composition instead of inheritance if you need to use methods from ColorSupplier
.
import java.util.Random; | ||
|
||
public class FigureSupplier extends ColorSupplier { | ||
private final static Random picker = new Random(); |
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 defining the number of figure types as a constant for better readability and maintainability. For example, private static final int FIGURE_TYPES_COUNT = 4;
.
public static Figure getRandomFigure() { | ||
return switch(picker.nextInt(4)) { | ||
case 0 -> new Circle(getRandomColor(), picker.nextInt(1, 50)); | ||
case 1 -> new Rectangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50)); | ||
case 2 -> new RightTriangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50)); | ||
case 3 -> new Square(getRandomColor(), picker.nextInt(1, 50)); | ||
default -> new Circle(Colors.WHITE, 10); | ||
}; | ||
} |
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 using static methods. Instead, create an instance of FigureSupplier
and call the method on that instance. This aligns with the checklist's recommendation to avoid static methods.
return switch(picker.nextInt(4)) { | ||
case 0 -> new Circle(getRandomColor(), picker.nextInt(1, 50)); | ||
case 1 -> new Rectangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50)); | ||
case 2 -> new RightTriangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50)); | ||
case 3 -> new Square(getRandomColor(), picker.nextInt(1, 50)); | ||
default -> new Circle(Colors.WHITE, 10); | ||
}; |
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.
Replace the magic number 4
with a constant, such as FIGURE_TYPES_COUNT
, to improve code readability and maintainability.
public double area() { | ||
return (firstBase + secondBase) * height; |
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 formula for the area of an isosceles trapezoid is incorrect. It should be ((firstBase + secondBase) / 2) * height
to correctly calculate the area.
package core.basesyntax; | ||
|
||
public class Main { | ||
public static void main(String args[]) { |
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.
It's a common convention to declare the main
method parameter as String[] args
instead of String args[]
. Consider changing it for consistency.
public static Figure[] listOfRandomFigures() { | ||
Figure[] array = new Figure[6]; | ||
|
||
for(int i = 0; i < 3; i++) { | ||
array[i] = FigureSupplier.getRandomFigure(); | ||
} | ||
|
||
for(int i = 3; i < 6; i++) { | ||
array[i] = FigureSupplier.getDefaultFigure(); | ||
} | ||
|
||
return array; | ||
} | ||
|
||
public static void printArray() { | ||
for(Figure i : listOfRandomFigures()) { | ||
i.draw(); | ||
} | ||
} |
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 using static methods for listOfRandomFigures
and printArray
. Consider creating an instance of Main
and calling these methods on that instance, aligning with the checklist's recommendation to avoid static methods.
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.
Review Summary
Great job on implementing the various classes and addressing most of the previous review comments! Your code is well-structured and adheres to the task requirements. Here are some key points and suggestions for further improvement:
-
Static Methods Usage: You've correctly moved away from static methods by creating instances of
FigureSupplier
andColorSupplier
. This is a good practice for object-oriented programming. -
Isosceles Trapezoid Area Calculation: The formula for calculating the area is now correct, ensuring accurate results.
-
Magic Numbers: You've improved readability by replacing the magic number
4
with a named constant. This makes your code more understandable and maintainable. -
Inheritance Misuse: The unnecessary inheritance from
ColorSupplier
inFigureSupplier
has been removed, aligning with proper design principles. -
Switch Statement Default Case: Although the default case in your switch statement is redundant due to the range of
picker.nextInt(randomNum)
, it's a minor issue. You can safely remove it for cleaner code.
Overall, your code meets the task requirements and is ready for further use. Remember to address any remaining issues in future projects to enhance your coding skills. 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! ✨
|
||
public class FigureSupplier { | ||
private final Random picker = new Random(); | ||
private final int randomNum = 4; |
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 use of the magic number 4
for randomNum
should be replaced with a named constant to improve code readability and maintainability. Consider defining a constant like private static final int NUMBER_OF_FIGURES = 4;
.
picker.nextInt(1, 50)); | ||
case 3 -> new Square(colorSupplier.getRandomColor(), | ||
picker.nextInt(1, 50)); | ||
default -> new Circle(Colors.WHITE, 10); |
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 default case in the switch statement is redundant because the picker.nextInt(randomNum)
will always return a value between 0 and 3. You can safely remove the default case.
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.
Let’s improve your solution ;)
@@ -0,0 +1,9 @@ | |||
package core.basesyntax; | |||
|
|||
public enum Colors { |
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.
public enum Colors { | |
public enum Color { |
|
||
public class FigureSupplier { | ||
private final Random picker = new Random(); | ||
private final int randomNum = 4; |
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.
it should be a constant
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.
what it?
picker.nextInt(1, 50)); | ||
case 3 -> new Square(colorSupplier.getRandomColor(), | ||
picker.nextInt(1, 50)); | ||
default -> new Circle(Colors.WHITE, 10); |
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.
IsoscelesTrapesoid missed
picker.nextInt(1, 50)); | ||
case 1 -> new Rectangle(colorSupplier.getRandomColor(), | ||
picker.nextInt(1, 50), | ||
picker.nextInt(1, 50)); | ||
case 2 -> new RightTriangle(colorSupplier.getRandomColor(), | ||
picker.nextInt(1, 50), | ||
picker.nextInt(1, 50)); | ||
case 3 -> new Square(colorSupplier.getRandomColor(), | ||
picker.nextInt(1, 50)); |
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.
Make numbers constant field
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Colors.WHITE, 10); |
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 same
public static Figure[] listOfRandomFigures() { | ||
Figure[] array = new Figure[6]; | ||
|
||
for (int i = 0; i < 3; i++) { | ||
array[i] = figureSupplier.getRandomFigure(); | ||
} | ||
|
||
for (int i = 3; i < 6; i++) { | ||
array[i] = figureSupplier.getDefaultFigure(); | ||
} | ||
|
||
return array; | ||
} | ||
|
||
public static void printArray() { | ||
for (Figure i : listOfRandomFigures()) { | ||
i.draw(); | ||
} | ||
} |
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.
these methods can be private
} | ||
|
||
public static void printArray() { | ||
for (Figure i : listOfRandomFigures()) { |
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.
create local variable for listOfRandomFigures()
|
||
import java.util.Random; | ||
|
||
public final class ColorSupplier { |
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.
public final class ColorSupplier { | |
public class ColorSupplier { |
public final class ColorSupplier { | ||
private final Random picker = new Random(); | ||
|
||
public Color getRandomColor() { |
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.
public Color getRandomColor() { | |
public String getRandomColor() { |
import java.util.Random; | ||
|
||
public final class ColorSupplier { | ||
private final Random picker = new Random(); |
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.
private final Random picker = new Random(); | |
private final Random random = new Random(); |
private final float radius; | ||
|
||
public Circle(Color color, float radius) { | ||
super(color, "Circle"); |
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.
super(color, "Circle"); | |
super(color); |
public class Circle extends Figure { | ||
private final float radius; | ||
|
||
public Circle(Color color, float radius) { |
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.
public Circle(Color color, float radius) { | |
public Circle(String color, float radius) { |
public Figure getRandomFigure() { | ||
final int figureCount = 5; | ||
final int startNum = 1; | ||
final int limitNum = 50; |
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.
final int limitNum = 50; | |
final int limitNum = 50; | |
String randomColor = colorSupplier.getRandomColor(); |
final int limitNum = 50; | ||
|
||
return switch (picker.nextInt(figureCount)) { | ||
case 0 -> new Circle(colorSupplier.getRandomColor(), |
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.
same for other figures
case 0 -> new Circle(colorSupplier.getRandomColor(), | |
case 0 -> new Circle(randomColor, |
|
||
return switch (picker.nextInt(figureCount)) { | ||
case 0 -> new Circle(colorSupplier.getRandomColor(), | ||
picker.nextInt(startNum, limitNum)); |
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.
create method separate method to get picker.nextInt(startNum, limitNum));
and reuse it
picker.nextInt(startNum, limitNum), | ||
picker.nextInt(startNum, limitNum), | ||
picker.nextInt(startNum, limitNum)); | ||
default -> new Circle(Color.WHITE, 10); |
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.
10 should be constant
private static final FigureSupplier figureSupplier = new FigureSupplier(); | ||
|
||
public static void main(String[] args) { | ||
printArray(); |
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.
redundant separate method, create Figure[] here, 6 - should be constant, use one for loop for this task
No description provided.