-
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
Solved the problem according to the principles of oop #1744
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.
Hello! 😊 Your code is almost there, but there are a few critical issues that need to be addressed before we can approve the pull request:
-
Main Method Logic: The first loop in the
Main
class is missing the logic to populate the first half of thefigures
array with random figures. You should callfigureSupplier.getRandomFigure()
within this loop to assign a random figure to each element in the first half of the array. This is crucial for the functionality of your application. -
Direct Access to
color
Field: Ensure that accessing thecolor
field directly in subclasses is intentional and consistent. If you have a getter method forcolor
, consider using it for better encapsulation and consistency across your codebase.
These changes are important to ensure your application functions correctly and adheres to good coding practices. Once you've made these adjustments, feel free to resubmit your pull request. Keep up the great work, and I'm looking forward to seeing your 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.
System.out.println("Figure: circle, area: " + calculateArea() + " sq. units, radius: " | ||
+ radius + " units, 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.
Ensure that accessing the color
field directly is intentional and consistent with how other subclasses of Figure
handle this field. If you have a getter method for color
, consider using it for consistency and encapsulation.
FigureSupplier figureSupplier = new FigureSupplier(); | ||
Figure[] figures = new Figure[6]; | ||
|
||
for (int i = 0; i < figures.length / 2; i++) { |
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 first loop is missing the logic to populate the first half of the figures
array with random figures. You should call figureSupplier.getRandomFigure()
within this loop to assign a random figure to each element in the first half of the array.
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.
Great job on addressing the previous issues in your code! 🎉 Your implementation is well-structured, and the logic in the Main
class is correctly set up to populate the figures
array with both random and default figures.
Here are a few points to consider for further improvement:
-
Output Formatting: Ensure spaces are correctly placed in the
draw
method's output string for theSquare
andRectangle
classes. This will enhance readability. -
Encapsulation: Use the
getColor()
method instead of directly accessing thecolor
field in your subclasses. This aligns with good encapsulation practices. -
Magic Numbers: Consider defining a constant for the number of figure types to improve code readability and maintainability.
These adjustments will not only make your code cleaner but also enhance its maintainability. Keep up the good work, and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
private final Random random = new Random(); | ||
|
||
public Figure getRandomFigure() { | ||
int figureType = random.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.
Consider defining a constant for the number of figure types (5) to avoid using magic numbers. This will make your code more readable and easier to maintain. For example, you could define private static final int FIGURE_TYPES_COUNT = 5;
and use it here.
public void draw() { | ||
System.out.println("Shape: isosceles trapezoid, area: " + calculateArea() | ||
+ " square units, first base: " + base1 + " units, second base: " + base2 | ||
+ " units, height: " + height + " units, 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.
Consider using getColor()
instead of accessing the color
field directly for consistency and better encapsulation. This aligns with the practice of using getter methods to access private fields.
System.out.println("Shape: rectangle, area: " + calculateArea() + "square units width: " | ||
+ width + "height units: " + height + "color units: " + getColor()); |
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 are missing spaces in the output string of the draw
method. Consider adding spaces after 'square units', 'width:', and 'height:' for better readability. The corrected string should look like: "Shape: rectangle, area: " + calculateArea() + " square units, width: " + width + " units, height: " + height + " units, color: " + getColor().
System.out.println("Figure: square, area: " + calculateArea() + "square units, side: " | ||
+ side + " color, units" + getColor()); |
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 are missing spaces in the output string of the draw
method. Consider adding spaces after 'square units,' and before 'color' for better readability. The corrected string should look like: "Figure: square, area: " + calculateArea() + " square units, side: " + side + " units, color: " + getColor().
No description provided.