Skip to content

Conversation

unknownpanic
Copy link

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.

Review Summary

Great job setting up the class structure for the figures! However, I'm requesting changes because several core functional requirements are missing, which prevents the program from working as intended.

The most critical issues are:

  1. Missing Area Calculation: None of the figure classes (Circle, Square, Rectangle, etc.) implement a method to calculate their area. This is a primary requirement. You'll need to add a method like getArea() to each figure and also update the draw() method to print this area as part of its output.

  2. Incorrect Figure Properties: Several figures have properties that make area calculation impossible. For example:

    • Rectangle needs length and width, not just a diagonal.
    • RightTriangle needs firstLeg and secondLeg instead of hypotenuse.
    • Circle must be defined by its radius, not circumference.
  3. FigureSupplier Logic: The getRandomFigure() method doesn't correctly generate figures that need more than one dimension (like Rectangle). It also returns null in its default case, which violates the project checklist (#12). Additionally, getDefaultFigure() creates a circle with a circumference of 10, but the task requires a radius of 10.

  4. Application Flow: In Application.java, the task requires you to first populate the entire array with figures in one loop, and then iterate through the completed array to draw them in a second, separate loop.

Please address these points to meet the core requirements. You're on the right track, and I'm here to help if you have questions!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


public class Application {
private static final int ARRAY_FIGURE_LENGTH = 4;
private static final FigureSupplier figureSupplier = new FigureSupplier();

Choose a reason for hiding this comment

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

While this works, the task guidelines (specifically checklist items #9 and #10) encourage creating instances of helper classes like FigureSupplier as local variables inside the method where they are used (in this case, main). This helps avoid static state and promotes better object-oriented design.

Consider moving this instantiation inside the main method.

Comment on lines 10 to 18
for (int i = 0; i < ARRAY_FIGURE_LENGTH; i++) {
if (i >= (ARRAY_FIGURE_LENGTH / 2)) {
figures[i] = figureSupplier.getDefaultFigure();
figures[i].toDraw();
} else {
figures[i] = figureSupplier.getRandomFigure();
figures[i].toDraw();
}
}

Choose a reason for hiding this comment

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

The task description requires you to first populate the entire array with figures and then, after the array is fully generated, iterate through it to display the details of each figure.

Currently, you are creating and drawing a figure in the same step. You should have two separate loops:

  1. A loop to populate the figures array.
  2. A second loop to iterate through the populated array and call the toDraw() method on each element.

@@ -0,0 +1,18 @@
package core.basesyntax;

public class Circle extends Figure {

Choose a reason for hiding this comment

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

This class is missing a crucial piece of behavior required by the task description. All figures must have a method to calculate and return their area. You should add a method like getArea() here.


public class Circle extends Figure {
private static final String FIGURE_NAME = "Circle";
private double circumFerence;

Choose a reason for hiding this comment

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

According to the task description, a Circle should be defined by its radius, not its circumference. This property should be named radius to match the requirements. Also, there's a small typo in the variable name; it should be circumference if you were to keep it.

Comment on lines 13 to 16
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", circumFerence: " + circumFerence);

Choose a reason for hiding this comment

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

The output format for the draw method is incomplete. The task description requires printing the area of the figure as well. The example format is: Figure: <type>, area: <value> sq. units, <prop1>: <value> units, .... Please update this method to include the calculated area in the output.

Comment on lines 13 to 16
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", hypotenuse: " + hypotenuse);

Choose a reason for hiding this comment

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

The output format for the draw method is incomplete. The task description requires printing the area of the figure as well. The example format is: Figure: <type>, area: <value> sq. units, <prop1>: <value> units, .... Please update this method to include the calculated area and all relevant properties in the output.

@@ -0,0 +1,19 @@
package core.basesyntax;

Choose a reason for hiding this comment

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

This violates checklist item #1: 'Don't begin class or method implementation with an empty line.' Please remove this redundant empty line.

@@ -0,0 +1,19 @@
package core.basesyntax;

public class Square extends Figure {

Choose a reason for hiding this comment

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

The task description requires that all figures must have a method to calculate and return their area. This class is missing that implementation. You need to add a method, for example public double getArea(), that returns the area of the square.


public class Square extends Figure {
private static final String FIGURE_NAME = "Square";
// Чи треба в кожному класі створювати одну і ту саму константу?

Choose a reason for hiding this comment

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

This violates checklist item #13: 'Use only eng in messages/code'. Please ensure all comments and output are in English to maintain code consistency.

Comment on lines 14 to 17
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", side: " + side);

Choose a reason for hiding this comment

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

The output format for the draw method is incomplete. The task description requires printing the area of the figure as well. The example format is: Figure: <type>, area: <value> sq. units, <prop1>: <value> units, .... Please update this method to include the calculated area in the output.

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

Excellent progress on the overall structure! The figure classes and area calculations are well-implemented. However, I'm requesting changes because there are a few critical bugs that prevent the program from meeting the requirements.

Here are the main issues to address:

  1. FigureSupplier returns null: In FigureSupplier.java, the getRandomFigure() method returns null in its default case, which will crash the program with a NullPointerException. This violates a key requirement to never return null.
  2. Incorrect Random Figure Generation: The getRandomFigure() method generates a single random value and reuses it for all dimensions of a figure. This means, for example, that your Rectangle will always be a Square. You need to generate a new, separate random number for each dimension.
  3. Bug in IsoscelesTrapezoid: The constructor for IsoscelesTrapezoid is missing the line this.height = height;, causing the area to always be calculated as zero.

Once those are fixed, please also review the output format to ensure it includes the required units (e.g., sq. units and units) as specified in the task description. You're very close to a complete solution!


✨ 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

private static final String FIGURE_NAME = "Circle";
private double radius;

public Circle(String color, double circumFerence) {

Choose a reason for hiding this comment

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

The parameter name circumFerence is misleading. The task requires the circle to be defined by its radius, and this value is being assigned to the radius field inside the constructor. Please rename the parameter to radius for clarity and to align with the task requirements.

Comment on lines 18 to 22
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", area: " + this.getArea()
+ ", radius: " + radius);

Choose a reason for hiding this comment

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

The output format is missing the units specified in the task description. The example format is Figure: <type>, area: <area> sq. units, <prop1>: <val1> units, .... Please add " sq. units" after the area and " units" after the radius to match the required format.


public String getRandomColor() {
int index = random.nextInt(colors.length);
return colors[index].toString();

Choose a reason for hiding this comment

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

This violates checklist item #14: "Use name() for getting String representation of enum constants".

The checklist advises against using .toString() because it can be overridden, which might lead to unexpected behavior. The .name() method is the standard and safer way to get the exact string representation of an enum constant. Please switch to using .name() here.

package core.basesyntax;

public interface FigureBehavior {
void toDraw();

Choose a reason for hiding this comment

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

While this is functionally correct, the method name toDraw() is not idiomatic in Java. Method names should typically start with a verb that describes the action. A more conventional name would be draw().

Please consider renaming this method to draw() here and in all the classes that implement it. This will make your code more readable and aligned with standard Java practices.


public Figure getRandomFigure() {
int index = random.nextInt(figures.length);
String nameOfFigure = figures[index].toString();

Choose a reason for hiding this comment

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

This violates checklist item #14: "Use name() for getting String representation of enum constants".

The checklist explains that .toString() can be overridden, making .name() a safer and more reliable choice for getting the string value of an enum constant.

Comment on lines 9 to 13
public IsoscelesTrapezoid(String color, double firstBase, double secondBase, double height) {
super(color);
this.firstBase = firstBase;
this.secondBase = secondBase;
}

Choose a reason for hiding this comment

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

There's a critical bug in this constructor. The height parameter is accepted but is never assigned to the this.height field. As a result, this.height will always be its default value of 0.0, and the getArea() method will always return 0.

You need to add the line this.height = height; inside the constructor to fix this.

Comment on lines 21 to 28
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", area: " + this.getArea()
+ ", firstBase: " + firstBase
+ ", seconfBase: " + secondBase
+ ", height: " + height);
}

Choose a reason for hiding this comment

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

This method has a few issues:

  1. Method Name: As mentioned in other files, the method should be named draw() to follow standard conventions and the task description.
  2. Output Format: The output is missing the units specified in the task description. You need to add " sq. units" after the area and " units" after each dimension (firstBase, secondBase, height).
  3. Typo: There is a typo in the output string on line 26: seconfBase should be secondBase.

Comment on lines 20 to 26
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", area: " + this.getArea()
+ ", length: " + length
+ ", width: " + width);
}

Choose a reason for hiding this comment

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

This method has two issues that need to be addressed:

  1. Method Name: The name toDraw() is unconventional. In Java, methods that perform an action are typically named with a verb, so draw() would be a more standard and readable name.
  2. Output Format: The task description specifies a clear output format that includes units. Please update the println statement to add " sq. units" after the area and " units" after the length and width values to match the requirement.

Comment on lines 20 to 26
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", area: " + this.getArea()
+ ", firstLeg: " + firstLeg
+ "secondLeg: " + secondLeg);
}

Choose a reason for hiding this comment

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

This method has a few issues that prevent it from meeting the task requirements:

  1. Method Name: The method should be named draw() to follow common Java conventions for action-based methods.
  2. Missing Units: The task description requires the output to include units, for example, area: 12.5 sq. units and firstLeg: 7 units. Please add " sq. units" and " units" to the output string.
  3. Formatting Error: There is a missing comma and space in the string on line 25. It should be + ", secondLeg: " + secondLeg instead of + "secondLeg: " + secondLeg. This will fix the output formatting.

Comment on lines 18 to 22
public void toDraw() {
System.out.println("Figure: " + FIGURE_NAME
+ ", color: " + this.getColor()
+ ", area: " + this.getArea()
+ ", side: " + side);

Choose a reason for hiding this comment

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

The output format is missing the units specified in the task description. The example format is Figure: <type>, area: <area> sq. units, <prop1>: <val1> units, ....

Please add " sq. units" after the area and " units" after the side to match the required format.

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

Excellent work fixing the critical bugs! The program now runs correctly, which is a fantastic achievement. I'm approving this solution to help you move forward, but please review these suggestions to align your code with best practices for future tasks.

Here are a few key areas for refinement:

  • In Figure.java, the getArea() method should be defined in its own separate interface to follow the interface segregation principle (checklist item #4).
  • Always use .name() instead of .toString() for getting the string value of enums, as seen in ColorSupplier.java (checklist item #14).
  • Avoid "magic numbers" by declaring values like 4 in Application.java and 10 in FigureSupplier.java as named constants (checklist item #7).
  • For better readability, assign random values to variables before passing them into constructors in FigureSupplier.java (checklist item #8).

You've made great progress. Keep up the excellent work!


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

Footnotes

  1. Rate AI review example


public class Application {
public static void main(String[] args) {
final int arrayLength = 4;

Choose a reason for hiding this comment

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

This is a "magic number". According to checklist item #7, all magic numbers should be declared as constants. It would be better to define this at the class level to give it a descriptive name.

For example:

public class Application {
    private static final int FIGURES_ARRAY_LENGTH = 4;

    public static void main(String[] args) {
        Figure[] figures = new Figure[FIGURES_ARRAY_LENGTH];
        // ...
    }
}

private static final String FIGURE_NAME = "Circle";
private double radius;

public Circle(String color, double circumFerence) {

Choose a reason for hiding this comment

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

The parameter name circumFerence is a bit misleading here, as the value passed is used as the radius. To make the code clearer, it's a good practice to name parameters to reflect what they represent. In this case, renaming it to radius would be more accurate.


public String getRandomColor() {
int index = random.nextInt(colors.length);
return colors[index].toString();

Choose a reason for hiding this comment

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

This violates checklist item #14: "Use name() for getting String representation of enum constants".

While toString() often works, it can be overridden. The name() method is guaranteed to return the exact name of the enum constant as it's declared in the source code, which is the safer and required approach for this task.

return color;
}

abstract double getArea();

Choose a reason for hiding this comment

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

This violates checklist item #4: "Don't put all behavior into a single interface if the methods are conceptually different from each other... the draw() and getArea() methods are not conceptually close to each other."

You've done a great job separating the draw() method into the FigureBehavior interface. To fully adhere to the requirement, the getArea() method should also be defined in its own separate interface (e.g., AreaCalculable). This would mean Figure would not need to be an abstract class, and concrete figures would implement both interfaces.


public Figure getRandomFigure() {
int index = random.nextInt(figures.length);
String nameOfFigure = figures[index].toString();

Choose a reason for hiding this comment

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

This violates checklist item #14: "Use name() for getting String representation of enum constants".

While toString() often works, it's safer to use name() because toString() can be overridden. Using name() ensures you always get the declared name of the enum constant.


switch (nameOfFigure) {
case "Circle":
return new Circle(randomColor, random.nextDouble());

Choose a reason for hiding this comment

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

This violates checklist item #8: "Creating a figure, don't pass expressions in the constructor. Create separate variables and pass them on for better code readability."

Instead of passing random.nextDouble() directly, you should assign it to a local variable first.

Example:

double radius = random.nextDouble();
return new Circle(randomColor, radius);

This rule applies to all the figure creation calls within this switch block.

}

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.

This line contains two "magic numbers", which violates checklist item #7: "All magic numbers in your code should be constants."

  1. The color "White" should be a constant. A good practice would be to use the Colors enum you've already created, like Colors.WHITE.name().
  2. The radius 10 should also be defined as a named constant, for example: private static final double DEFAULT_RADIUS = 10;.

+ ", color: " + this.getColor()
+ ", area: " + this.getArea() + " sq. units"
+ ", firstBase: " + firstBase + " units"
+ ", seconfBase: " + secondBase + " units"

Choose a reason for hiding this comment

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

There's a small typo here. It should be secondBase to match the variable name and the logical property name.

Copy link

@Elena-Bruyako Elena-Bruyako 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 14 to 20
figures[i] = figureSupplier.getRandomFigure();
}
}

for (Figure figure : figures) {
figure.draw();
}

Choose a reason for hiding this comment

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

Suggested change
figures[i] = figureSupplier.getRandomFigure();
}
}
for (Figure figure : figures) {
figure.draw();
}
figures[i] = figureSupplier.getRandomFigure();
}
figures[i].draw();
}

@@ -0,0 +1,10 @@
package core.basesyntax;

public enum Colors {

Choose a reason for hiding this comment

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

enum name should be singular according to the naming convention

Suggested change
public enum Colors {
public enum Color {

@@ -0,0 +1,5 @@
package core.basesyntax;

public interface AreaCalculable {

Choose a reason for hiding this comment

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

Suggested change
public interface AreaCalculable {
public interface AreaCalculator {

@@ -0,0 +1,5 @@
package core.basesyntax;

public interface FigureBehavior {

Choose a reason for hiding this comment

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

Suggested change
public interface FigureBehavior {
public interface Drawable {

}

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

Choose a reason for hiding this comment

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

use WHITE from enum

@@ -0,0 +1,9 @@
package core.basesyntax;

public enum Figures {

Choose a reason for hiding this comment

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

Suggested change
public enum Figures {
public enum FigureName {

package core.basesyntax;

public enum Figures {
Circle,

Choose a reason for hiding this comment

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

read how to name enum values

String randomColor = colorSupplier.getRandomColor();

switch (nameOfFigure) {
case "Circle":

Choose a reason for hiding this comment

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

you can use your FigureName enum values

package core.basesyntax;

public class Circle extends Figure {
private static final String FIGURE_NAME = "Circle";

Choose a reason for hiding this comment

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

you don't neeed constant if you have FigureName enum

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