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

hw-1-jv-oop-advanced #1741

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

Conversation

Oleksandr19891989
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 implementation is mostly correct and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Magic Numbers: The use of magic numbers, such as 5 in random.nextInt(5), should be replaced with constants. This will enhance the readability and maintainability of your code.

  2. Code Readability: For better readability, it's recommended to create separate variables for random values before passing them to constructors. This small change can make your code much easier to understand.

  3. Constructor Formatting: There are minor formatting issues in the constructor parameter lists, such as missing or extra spaces around commas. These should be corrected for consistency and readability.

  4. super.draw() Calls: Ensure that the super.draw() calls are necessary. If the Figure class does not have a draw() method or if it does not need to be called, these lines should be removed.

  5. Interface Definition: Make sure that the Measurable interface is defined and includes the getArea() method, as its absence will lead to compilation errors.

Addressing these issues will not only improve the quality of your code but also ensure it functions correctly and efficiently. Keep up the great work, and I'm confident you'll nail it with these adjustments! 😊

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

src/main/java/core/basesyntax/Circle.java Outdated Show resolved Hide resolved

@Override
public void draw() {
super.draw();

Choose a reason for hiding this comment

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

Ensure that the super.draw() call is necessary. This depends on the implementation of the Figure class. If Figure does not have a draw() method or if it does not need to be called, this line can be removed.

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

public abstract class Figure implements Drawable,Measurable{

Choose a reason for hiding this comment

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

Ensure that the Measurable interface is defined and includes the getArea() method, as it is used in the draw() method. If Measurable is not defined, this will cause a compilation error.


public Figure getRandomFigure() {
String color = colorSupplier.getRandomColor();
switch (random.nextInt(5)) {

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 instead of using the magic number 5. This will improve code readability and maintainability. For example, private static final int FIGURE_TYPES_COUNT = 5; and use it in random.nextInt(FIGURE_TYPES_COUNT).

Comment on lines 13 to 21
return new Square(color, random.nextInt(10) + 1);
case 1:
return new Rectangle(color, random.nextInt(10) + 1, random.nextInt(10) + 1);
case 2:
return new RightTriangle(color, random.nextInt(10) + 1, random.nextInt(10) + 1);
case 3:
return new Circle(color, random.nextInt(10) + 1);
default:
return new IsoscelesTrapezoid(color, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1);

Choose a reason for hiding this comment

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

It's recommended to create separate variables for random values before passing them to constructors. This improves code readability. For example, int side = random.nextInt(10) + 1; and then use new Square(color, side);.


@Override
public void draw() {
super.draw();

Choose a reason for hiding this comment

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

Ensure that the super.draw() call is necessary. This depends on the implementation of the Figure class. If Figure does not have a draw() method or if it does not need to be called, this line can be removed.

public class Square extends Figure {
private double side;

public Square(String color,double side) {

Choose a reason for hiding this comment

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

There is a missing space after the comma in the constructor parameter list String color,double side. It should be String color, double side.


public Square(String color,double side) {
super(color);
this.side=side;

Choose a reason for hiding this comment

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

There should be spaces around the assignment operator for better readability: this.side = side;.


@Override
public void draw() {
super.draw();

Choose a reason for hiding this comment

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

Ensure that the super.draw() call is necessary. This depends on the implementation of the Figure class. If Figure does not have a draw() method or if it does not need to be called, this line can be removed.

Choose a reason for hiding this comment

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

Agree


@Override
public double getArea() {
return side*side;

Choose a reason for hiding this comment

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

There should be spaces around the multiplication operator for better readability: return side * side;.

Copy link

@okuzan okuzan left a comment

Choose a reason for hiding this comment

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

Please make sure build passes locally (with mvn clean package) before requesting mentors' review

Copy link

@ahoienko ahoienko left a comment

Choose a reason for hiding this comment

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

Nice, left some comments

import java.util.Random;

public class ColorSupplier {
private static final String[] COLORS = {"red", "green", "blue", "yellow", "black", "white"};

Choose a reason for hiding this comment

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

Better to create Color enum, and use it in all figures as field. It would be easier and more clear to extend code. And also you would avoid issues when someone made a mistake writing some color

Comment on lines 14 to 34
int side = random.nextInt(10) + 1;
return new Square(color, side);
}
case 1: {
int width = random.nextInt(10) + 1;
int height = random.nextInt(10) + 1;
return new Rectangle(color, width, height);
}
case 2: {
int base = random.nextInt(10) + 1;
int height = random.nextInt(10) + 1;
return new RightTriangle(color, base, height);
}
case 3: {
int radius = random.nextInt(10) + 1;
return new Circle(color, radius);
}
default: {
int base1 = random.nextInt(10) + 1;
int base2 = random.nextInt(10) + 1;
int height = random.nextInt(10) + 1;

Choose a reason for hiding this comment

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

magic numbers

public class Main {
public static void main(String[] args) {
FigureSupplier figureSupplier = new FigureSupplier();
Figure[] figures = new Figure[6];

Choose a reason for hiding this comment

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

Magic number

Comment on lines 9 to 22
for (int i = 0; i < figures.length / 2; i++) {
figures[i] = figureSupplier.getRandomFigure();
}

// Generate default figures for the second half
for (int i = figures.length / 2; i < figures.length; i++) {
figures[i] = figureSupplier.getDefaultFigure();
}

// Display all figures
for (Figure figure : figures) {
figure.draw();
System.out.println();
}

Choose a reason for hiding this comment

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

It is possible to make everything in one loop

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

public interface Measurable {

Choose a reason for hiding this comment

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

Suggested change
public interface Measurable {
public interface AreaCalcualtor{


@Override
public void draw() {
super.draw();

Choose a reason for hiding this comment

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

Agree

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

public Color getRandomColor() {
Copy link

Choose a reason for hiding this comment

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

in task description, this method should return String

private double height;

public IsoscelesTrapezoid(Color color, double base1, double base2, double height) {
super(String.valueOf(color));
Copy link

Choose a reason for hiding this comment

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

we should pass String to constructor.
Also, to get string representation of enum use .name()

Comment on lines 4 to 5
private double base1;
private double base2;
Copy link

Choose a reason for hiding this comment

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

numbers in naming are usually bad, let's name them topBase bottomBase

package core.basesyntax;

public enum Color {
RED, GREEN, BLUE, YELLOW, BLACK, WHITE;

Choose a reason for hiding this comment

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

Suggested change
RED, GREEN, BLUE, YELLOW, BLACK, WHITE;
RED,
GREEN,
BLUE,
YELLOW,
BLACK,
WHITE

Choose a reason for hiding this comment

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

not fixed


public String getRandomColor() {
Color[] colors = Color.values();
return colors[RANDOM.nextInt(colors.length)].toString();

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

not fixed

String color = colorSupplier.getRandomColor();
switch (random.nextInt(FIGURE_TYPES_COUNT)) {
case 0: {
int side = random.nextInt(MAX_DIMENSION) + MIN_DIMENSION;

Choose a reason for hiding this comment

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

let's avoid duplication of code
create separate method to get random side

Choose a reason for hiding this comment

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

not fixed

public class Circle extends Figure {
private double radius;

public Circle(Color color, double 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, double radius) {
public Circle(String color, double radius) {

Choose a reason for hiding this comment

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

For each figure

Choose a reason for hiding this comment

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

not fixed

private double radius;

public Circle(Color color, double radius) {
super(color.name());

Choose a reason for hiding this comment

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

Suggested change
super(color.name());
super(color);

Choose a reason for hiding this comment

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

not fixed

}
}

for (Figure figure : figures) {

Choose a reason for hiding this comment

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

use one for loop to implement main method

Choose a reason for hiding this comment

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

not fixed

Comment on lines +6 to +7
final int arraySize = (int) (Math.random() * 10) + 1;
Figure[] figures = new Figure[arraySize];

Choose a reason for hiding this comment

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

create constant SIZE_OF_ARRAY for example 6

Suggested change
final int arraySize = (int) (Math.random() * 10) + 1;
Figure[] figures = new Figure[arraySize];
Figure[] figures = new Figure[SIZE_OF_ARRAY];

Choose a reason for hiding this comment

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

not fixed

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.

fix all previous comments

public class Circle extends Figure {
private double radius;

public Circle(Color color, double radius) {

Choose a reason for hiding this comment

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

not fixed

private double radius;

public Circle(Color color, double radius) {
super(color.name());

Choose a reason for hiding this comment

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

not fixed

package core.basesyntax;

public enum Color {
RED, GREEN, BLUE, YELLOW, BLACK, WHITE;

Choose a reason for hiding this comment

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

not fixed


public String getRandomColor() {
Color[] colors = Color.values();
return colors[RANDOM.nextInt(colors.length)].toString();

Choose a reason for hiding this comment

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

not fixed

String color = colorSupplier.getRandomColor();
switch (random.nextInt(FIGURE_TYPES_COUNT)) {
case 0: {
int side = random.nextInt(MAX_DIMENSION) + MIN_DIMENSION;

Choose a reason for hiding this comment

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

not fixed

Comment on lines +6 to +7
final int arraySize = (int) (Math.random() * 10) + 1;
Figure[] figures = new Figure[arraySize];

Choose a reason for hiding this comment

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

not fixed

}
}

for (Figure figure : figures) {

Choose a reason for hiding this comment

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

not fixed

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.

6 participants