-
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
done #1779
base: master
Are you sure you want to change the base?
done #1779
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.
Hello! 😊 You've done a great job implementing the classes and methods, and your code mostly meets the task requirements. However, there are a couple of critical issues that need to be addressed before we can approve the pull request:
-
Returning
null
from a method: In theFigureSupplier
class, thegetRandomFigure()
method returnsnull
in the default case of the switch statement. This could lead toNullPointerException
and is against best practices. Consider returning a default figure or handling this case differently. -
Magic numbers: The use of magic numbers, such as
5
in therandom.nextInt(5)
call, should be replaced with constants. This will improve the readability and maintainability of your code.
Once these issues are resolved, your code will be in great shape! Keep up the good work, and I'm looking forward to seeing the improvements. 🚀
✨ 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.
ColorSupplier colorSupplier = new ColorSupplier(); | ||
Random random = new Random(); | ||
String color = colorSupplier.getRandomColor(); | ||
int figureType = 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 (5) to avoid magic numbers and improve code readability.
random.nextDouble() * 10, | ||
random.nextDouble() * 10, | ||
random.nextDouble() * 10); | ||
default: return null; |
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.
Returning null
from a method is a bad practice. Instead of returning null
in the default case, you could return a default figure or handle this case differently to avoid potential NullPointerException
.
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
Great job on implementing the various classes and interfaces! Your code is well-structured and demonstrates a solid understanding of object-oriented principles. Here are some key points from the review:
-
Magic Numbers: You've successfully replaced the magic number
5
with a constantFIGURE_COUNT
in theFigureSupplier
class, which enhances readability and maintainability. This is a good practice to follow in future projects as well. -
Null Handling: The
getRandomFigure()
method in theFigureSupplier
class no longer returnsnull
, which is a significant improvement. Instead, it now returns a default figure using thegetDefaultFigure()
method, ensuring that your code is more robust and less prone to errors. -
Class Implementations: All classes, such as
Circle
,Rectangle
,Square
,RightTriangle
, andIsoscelesTrapezoid
, are well-implemented. They correctly extend theFigure
class and override necessary methods likegetArea
anddraw
. Your constructors are also well-defined, initializing attributes appropriately. -
Interfaces and Abstract Classes: The
Shape
andColored
interfaces are correctly defined, and theFigure
abstract class implements them properly. This setup allows for flexibility and scalability in your code. -
Main Class: The
Main
class is effectively set up to demonstrate the functionality of yourFigureSupplier
class, showcasing your understanding of how to integrate and test your components.
Overall, your code meets the task requirements and constraints. While there are no critical issues, always strive to review and refine your code based on feedback. This will help you improve and learn from any mistakes. Keep up the great work, and continue to build on your skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
ColorSupplier colorSupplier = new ColorSupplier(); | ||
Random random = new Random(); | ||
String color = colorSupplier.getRandomColor(); | ||
final int figureType = 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 replacing the magic number 5
with a named constant to improve readability and maintainability. For example, you could define a constant private static final int NUMBER_OF_FIGURE_TYPES = 5;
and use it here.
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.
Good job! Let’s improve your solution ;)
|
||
|
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.
Leave only one empty line at the end of the file (check it everywhere)
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.
Let’s create separate enum class Color
private static final String[] COLORS = {"Red", "Green", "Blue", "Yellow", "Black", "White"}; | ||
|
||
public String getRandomColor() { | ||
Random random = new Random(); |
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.
Make Random private final class level variable
public interface Colored { | ||
String getColor(); | ||
} | ||
|
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.
remove this interface Color is state (not behavior)
public abstract class Figure implements Shape, Colored { | ||
private String 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.
public abstract class Figure implements Shape, Colored { | |
private String color; | |
public abstract class Figure { | |
private Color color; | |
ColorSupplier colorSupplier = new ColorSupplier(); | ||
Random random = new Random(); |
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.
should be class level variable
ColorSupplier colorSupplier = new ColorSupplier(); | ||
Random random = new Random(); | ||
String color = colorSupplier.getRandomColor(); | ||
final int figureType = 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.
use constant
|
||
switch (figureType) { | ||
case 0: return new Square(color, | ||
random.nextDouble() * 10); |
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 same. make 10 constant and reuse it
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle("White", 10); |
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 constants
double getArea(); | ||
|
||
void 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.
create interfaces AreaCalculator with method getArea()
and Drawable with draw()
No description provided.