-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(DEVELOP): create Figure structure #1951
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
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.
Review Summary
Decision: REQUEST_CHANGES — there are a few critical requirement violations that block full compliance.
Blocking issues to fix:
-
draw() outputs missing units (requirements 1.5, 3.8)
- Files:
Circle.java
(e.g., radius/area),Square.java
(side/area),Rectangle.java
(width/height/area),RightTriangle.java
(base/height/area),IsoscelesTrapezoid.java
(base/height/side/area) - Why: The task requires each dimension and area to be printed with “units”. Missing units makes the output non-compliant and can cause test failures.
- How: Update each draw() to include units, e.g.,
radius: <value> units
,area: <value> units
.
- Files:
-
ColorSupplier return type (requirement 1.6)
- File:
src/main/java/core/basesyntax/service/ColorSupplier.java
, methodgetRandomColor()
- Why: Must return a random color string, not a
Color
enum. - How: Change signature to return
String
and returncolors[randomIndex].name()
.
- File:
-
FigureSupplier collaborator scope and magic number (checklist 6, 7)
- File:
src/main/java/core/basesyntax/service/FigureSupplier.java
- Why: Instantiating
ColorSupplier
insidegetRandomFigure()
and using5
directly both violate checklist requirements and can lead to inefficiency and brittle code. - How: Make
ColorSupplier
a field initialized in the class. Replace5
inrandom.nextInt(5) + 1
with a named constant likeFIGURE_TYPES_COUNT
.
- File:
-
Enum string usage and default case handling (checklist 12, 14)
- File:
FigureSupplier.java
- Why: If
getRandomColor()
returnsColor
, use.name()
; if returningString
, remove.toString()
. The switchdefault
should return a valid figure to ensure the method always returns a figure. - How: Adjust color assignment accordingly. In the switch
default
, return a valid default figure instead of throwing aRuntimeException
.
- File:
Minor notes:
- Ensure all places that output colors use
name()
if working with enums.
You’ve done a solid job on structure and main flow. With these targeted fixes, your solution should fully meet the requirements. Keep it up!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review
button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor
tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
System.out.println("Circle: " | ||
+ "color: " + getColor() | ||
+ ", radius: " + getRadius() | ||
+ ", area: " + getArea()); |
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 draw()
output does not include units for the radius or area, as required by the task description and checklist (requirement 1.5, 3.8: "Each dimension with units 'units'"). Consider updating the output to include units, e.g., radius: X units
, area: Y units
.
+ ", base: " + getBase() | ||
+ ", height: " + getHeight() | ||
+ ", side: " + getSide() | ||
+ ", area: " + getArea()); |
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 draw()
output does not include units for the base, height, side, or area, as required by the task description and checklist (requirement 1.5, 3.8: "Each dimension with units 'units'"). Consider updating the output to include units, e.g., base: X units
, height: Y units
, side: Z units
, area: Y units
.
+ "color: " + getColor() | ||
+ ", width: " + getWidth() | ||
+ ", height: " + getHeight() | ||
+ ", area: " + getArea()); |
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 draw()
output does not include units for the width, height, or area, as required by the task description and checklist (requirement 1.5, 3.8: "Each dimension with units 'units'"). Consider updating the output to include units, e.g., width: X units
, height: Y units
, area: Y units
.
+ "color: " + getColor() | ||
+ ", base: " + getFirstLeg() | ||
+ ", height: " + getSecondLeg() | ||
+ ", area: " + getArea()); |
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 draw()
output does not include units for the base, height, or area, as required by the task description and checklist (requirement 1.5, 3.8: "Each dimension with units 'units'"). Consider updating the output to include units, e.g., base: X units
, height: Y units
, area: Y units
.
System.out.println("Square: " | ||
+ "color: " + getColor() | ||
+ ", side: " + getSide() | ||
+ ", area: " + getArea()); |
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 draw()
output does not include units for the side or area, as required by the task description and checklist (requirement 1.5, 3.8: "Each dimension with units 'units'"). Consider updating the output to include units, e.g., side: X units
, area: Y units
.
public Color getRandomColor() { | ||
int randomIndex = random.nextInt(colors.length); | ||
|
||
return colors[randomIndex]; |
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 method getRandomColor()
returns a Color
enum, but the requirements specify it should return a String
(requirement 1.6: "returns a random color string"). Consider changing the return type to String
and returning colors[randomIndex].name()
.
private Random random = new Random(); | ||
|
||
public Figure getRandomFigure() { | ||
ColorSupplier colorSupplier = new 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.
The ColorSupplier
is instantiated inside getRandomFigure()
. According to checklist item 6, persistent collaborators like ColorSupplier
should be fields, not local variables. Move ColorSupplier
to a field in the class.
|
||
public Figure getRandomFigure() { | ||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
int randomIndex = random.nextInt(5) + 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.
The number 5 in random.nextInt(5) + 1
is a magic number. According to checklist item 7, use a named constant for the number of figure types instead of a magic number.
public Figure getRandomFigure() { | ||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
int randomIndex = random.nextInt(5) + 1; | ||
String color = colorSupplier.getRandomColor().toString(); |
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.
If getRandomColor()
returns a Color
enum, you should use .name()
instead of .toString()
when assigning to color
, as per checklist item 14. If it returns a String
, .toString()
is redundant and should be removed.
side = random.nextInt(10) + 1; | ||
return new core.basesyntax.model.IsoscelesTrapezoid(base, height, side, color); | ||
default: | ||
throw new RuntimeException("Can't create figure"); |
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.
In the switch's default
case, you throw a RuntimeException
. Checklist item 12 states: "Do not return null from methods like getRandomFigure(), getDefaultFigure(), or any switch-based factory logic. Ensure a valid Figure is always returned, using default case if switch is used." Instead of throwing, return a valid default figure.
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
Decision: Request changes because output formatting violates explicit requirements and will likely fail tests.
Critical issues to fix (blockers):
- Area units must be exactly "sq. units" in all draw() outputs.
- Files and suggested fixes:
- src/main/java/core/basesyntax/model/Circle.java: In
draw()
(line with area printing), append" sq. units"
aftergetArea()
.- Example:
", area: " + getArea() + " sq. units"
- Example:
- src/main/java/core/basesyntax/model/IsoscelesTrapezoid.java: Replace "square units" with
"sq. units"
indraw()
. - src/main/java/core/basesyntax/model/Rectangle.java: Replace "square units" with
"sq. units"
indraw()
. - src/main/java/core/basesyntax/model/RightTriangle.java: Replace "square units" with
"sq. units"
indraw()
. - src/main/java/core/basesyntax/model/Square.java: Replace "square units" with
"sq. units"
indraw()
.
- src/main/java/core/basesyntax/model/Circle.java: In
- Why: The spec requires the exact format
area: <value> sq. units
. Mismatches will break output-based tests.
- Files and suggested fixes:
- RightTriangle color output format is incorrect.
- File: src/main/java/core/basesyntax/model/RightTriangle.java
- Issue:
draw()
appends " units" to the color (e.g.,color: yellow units
). - Fix: Print only the color string:
"color: " + getColor()
without extra text.
Minor (non-blocking) note:
- FigureSupplier uses 1-based random switch index. It’s fine, but 0-based is more idiomatic.
You’ve done a solid job with class structure, area calculations, and suppliers. Once you align the output strings with the exact required format, your solution should fully pass. Keep it up!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review
button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor
tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
System.out.println("Circle: " | ||
+ "color: " + getColor() | ||
+ ", radius: " + getRadius() + " units" | ||
+ ", area: " + getArea()); |
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 area output in draw() is missing the required units. It should be:
+ ", area: " + getArea() + " sq. units"
This violates the requirement that area must be printed with units (e.g., 'area: 25.0 sq. units').
+ ", base: " + getBase() + " units" | ||
+ ", height: " + getHeight() + " units" | ||
+ ", side: " + getSide() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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 area output in draw() should use "sq. units" instead of "square units" to match the required format: 'area: sq. units'.
+ "color: " + getColor() | ||
+ ", width: " + getWidth() + " units" | ||
+ ", height: " + getHeight() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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 area output in draw() should use "sq. units" instead of "square units" to match the required format: 'area: sq. units'.
@Override | ||
public void draw() { | ||
System.out.println("RightTriangle: " | ||
+ "color: " + getColor() + " units" |
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 output in draw() incorrectly appends " units" to the color. It should be just the color string, e.g., 'color: yellow'.
+ "color: " + getColor() + " units" | ||
+ ", base: " + getFirstLeg() + " units" | ||
+ ", height: " + getSecondLeg() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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 area output in draw() should use "sq. units" instead of "square units" to match the required format: 'area: sq. units'.
System.out.println("Square: " | ||
+ "color: " + getColor() | ||
+ ", side: " + getSide() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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 area output in draw() should use "sq. units" instead of "square units" to match the required format: 'area: sq. units'.
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
Educational approval: Great progress overall—your design cleanly follows OOP principles, suppliers are used via composition, and Main correctly creates and draws figures. Nice job keeping constants, avoiding static business logic, and ensuring no nulls are returned.
However, there’s a small output-format issue that can break tests:
- src/main/java/core/basesyntax/model/Circle.java: In
draw()
(likely around the line where you print area), you print "area: ... square units" but the requirement is exactly "area: ... sq. units". - src/main/java/core/basesyntax/model/Rectangle.java: Same as above in
draw()
.
Why this matters: tests compare exact strings; any deviation like "square units" won’t match. How to fix: change the hardcoded unit substring to "sq. units" in both draw()
methods while keeping the rest of the format unchanged.
Everything else looks solid—area calculations, constructors, and the rest of the draw outputs are correct. Make that quick tweak and you should be all set. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
System.out.println("Circle: " | ||
+ "color: " + getColor() | ||
+ ", radius: " + getRadius() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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.
This violates the requirement for exact output format: area must be printed as "area: ... sq. units" (not "square units").
See task description and previous review: output must be exactly "sq. units" to pass tests.
+ "color: " + getColor() | ||
+ ", width: " + getWidth() + " units" | ||
+ ", height: " + getHeight() + " units" | ||
+ ", area: " + getArea() + " square units"); |
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.
This violates the requirement for exact output format: area must be printed as "area: ... sq. units" (not "square units").
See task description and previous review: output must be exactly "sq. units" to pass tests.
No description provided.