-
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
hw-1-jv-oop-advanced #1741
base: master
Are you sure you want to change the base?
hw-1-jv-oop-advanced #1741
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.
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:
-
Magic Numbers: The use of magic numbers, such as
5
inrandom.nextInt(5)
, should be replaced with constants. This will enhance the readability and maintainability of your code. -
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.
-
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.
-
super.draw()
Calls: Ensure that thesuper.draw()
calls are necessary. If theFigure
class does not have adraw()
method or if it does not need to be called, these lines should be removed. -
Interface Definition: Make sure that the
Measurable
interface is defined and includes thegetArea()
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.
|
||
@Override | ||
public void draw() { | ||
super.draw(); |
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 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{ |
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 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)) { |
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 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)
.
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); |
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.
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(); |
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 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) { |
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 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; |
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 should be spaces around the assignment operator for better readability: this.side = side;
.
|
||
@Override | ||
public void draw() { | ||
super.draw(); |
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 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.
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.
Agree
|
||
@Override | ||
public double getArea() { | ||
return side*side; |
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 should be spaces around the multiplication operator for better readability: return side * side;
.
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.
Please make sure build passes locally (with mvn clean package
) before requesting mentors' review
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.
Nice, left some comments
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private static final String[] COLORS = {"red", "green", "blue", "yellow", "black", "white"}; |
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.
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
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; |
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.
magic numbers
public class Main { | ||
public static void main(String[] args) { | ||
FigureSupplier figureSupplier = new FigureSupplier(); | ||
Figure[] figures = new Figure[6]; |
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.
Magic number
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(); | ||
} |
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.
It is possible to make everything in one loop
@@ -0,0 +1,5 @@ | |||
package core.basesyntax; | |||
|
|||
public interface Measurable { |
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.
public interface Measurable { | |
public interface AreaCalcualtor{ |
|
||
@Override | ||
public void draw() { | ||
super.draw(); |
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.
Agree
public class ColorSupplier { | ||
private static final Random RANDOM = new Random(); | ||
|
||
public Color getRandomColor() { |
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 task description, this method should return String
private double height; | ||
|
||
public IsoscelesTrapezoid(Color color, double base1, double base2, double height) { | ||
super(String.valueOf(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.
we should pass String to constructor.
Also, to get string representation of enum use .name()
private double base1; | ||
private double base2; |
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.
numbers in naming are usually bad, let's name them topBase bottomBase
package core.basesyntax; | ||
|
||
public enum Color { | ||
RED, GREEN, BLUE, YELLOW, BLACK, WHITE; |
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.
RED, GREEN, BLUE, YELLOW, BLACK, WHITE; | |
RED, | |
GREEN, | |
BLUE, | |
YELLOW, | |
BLACK, | |
WHITE |
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.
not fixed
|
||
public String getRandomColor() { | ||
Color[] colors = Color.values(); | ||
return colors[RANDOM.nextInt(colors.length)].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.
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.
not fixed
String color = colorSupplier.getRandomColor(); | ||
switch (random.nextInt(FIGURE_TYPES_COUNT)) { | ||
case 0: { | ||
int side = random.nextInt(MAX_DIMENSION) + MIN_DIMENSION; |
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.
let's avoid duplication of code
create separate method to get random side
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.
not fixed
public class Circle extends Figure { | ||
private double radius; | ||
|
||
public Circle(Color color, double radius) { |
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.
public Circle(Color color, double radius) { | |
public Circle(String color, double radius) { |
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.
For each 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.
not fixed
private double radius; | ||
|
||
public Circle(Color color, double radius) { | ||
super(color.name()); |
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.
super(color.name()); | |
super(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.
not fixed
} | ||
} | ||
|
||
for (Figure figure : figures) { |
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.
use one for loop to implement main method
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.
not fixed
final int arraySize = (int) (Math.random() * 10) + 1; | ||
Figure[] figures = new Figure[arraySize]; |
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.
create constant SIZE_OF_ARRAY for example 6
final int arraySize = (int) (Math.random() * 10) + 1; | |
Figure[] figures = new Figure[arraySize]; | |
Figure[] figures = new Figure[SIZE_OF_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.
not fixed
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.
fix all previous comments
public class Circle extends Figure { | ||
private double radius; | ||
|
||
public Circle(Color color, double radius) { |
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.
not fixed
private double radius; | ||
|
||
public Circle(Color color, double radius) { | ||
super(color.name()); |
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.
not fixed
package core.basesyntax; | ||
|
||
public enum Color { | ||
RED, GREEN, BLUE, YELLOW, BLACK, WHITE; |
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.
not fixed
|
||
public String getRandomColor() { | ||
Color[] colors = Color.values(); | ||
return colors[RANDOM.nextInt(colors.length)].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.
not fixed
String color = colorSupplier.getRandomColor(); | ||
switch (random.nextInt(FIGURE_TYPES_COUNT)) { | ||
case 0: { | ||
int side = random.nextInt(MAX_DIMENSION) + MIN_DIMENSION; |
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.
not fixed
final int arraySize = (int) (Math.random() * 10) + 1; | ||
Figure[] figures = new Figure[arraySize]; |
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.
not fixed
} | ||
} | ||
|
||
for (Figure figure : figures) { |
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.
not fixed
No description provided.