Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Done #1775

wants to merge 13 commits into from

Conversation

mizuo-san
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.


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:

  1. Static Methods Usage: The use of static methods in FigureSupplier and ColorSupplier 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.

  2. 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.

  3. Magic Numbers: The presence of magic numbers, such as 4 in the FigureSupplier, should be replaced with named constants for better readability and maintainability.

  4. Inheritance Misuse: Extending ColorSupplier in FigureSupplier 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 {

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();

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;.

Comment on lines 8 to 16
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);
};
}

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.

Comment on lines 9 to 15
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);
};

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.

Comment on lines 16 to 17
public double area() {
return (firstBase + secondBase) * height;

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[]) {

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.

Comment on lines 8 to 26
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();
}
}

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.

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 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:

  1. Static Methods Usage: You've correctly moved away from static methods by creating instances of FigureSupplier and ColorSupplier. This is a good practice for object-oriented programming.

  2. Isosceles Trapezoid Area Calculation: The formula for calculating the area is now correct, ensuring accurate results.

  3. Magic Numbers: You've improved readability by replacing the magic number 4 with a named constant. This makes your code more understandable and maintainable.

  4. Inheritance Misuse: The unnecessary inheritance from ColorSupplier in FigureSupplier has been removed, aligning with proper design principles.

  5. 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;

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);

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.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a 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 {

Choose a reason for hiding this comment

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

Suggested change
public enum Colors {
public enum Color {


public class FigureSupplier {
private final Random picker = new Random();
private final int randomNum = 4;

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

Copy link
Author

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);

Choose a reason for hiding this comment

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

IsoscelesTrapesoid missed

Comment on lines 13 to 21
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));

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);

Choose a reason for hiding this comment

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

the same

Comment on lines 10 to 28
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();
}
}

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()) {

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 {

Choose a reason for hiding this comment

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

Suggested change
public final class ColorSupplier {
public class ColorSupplier {

public final class ColorSupplier {
private final Random picker = new Random();

public Color getRandomColor() {

Choose a reason for hiding this comment

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

Suggested change
public Color getRandomColor() {
public String getRandomColor() {

import java.util.Random;

public final class ColorSupplier {
private final Random picker = new Random();

Choose a reason for hiding this comment

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

Suggested change
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");

Choose a reason for hiding this comment

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

Suggested change
super(color, "Circle");
super(color);

public class Circle extends Figure {
private final float radius;

public Circle(Color color, float radius) {

Choose a reason for hiding this comment

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

Suggested change
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;

Choose a reason for hiding this comment

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

Suggested change
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(),

Choose a reason for hiding this comment

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

same for other figures

Suggested change
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));

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);

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();

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

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.

4 participants