-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #1735
base: master
Are you sure you want to change the base?
done #1735
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 you've made a great start, there are a few critical issues that need to be addressed to meet the core requirements of the task:
-
Ball
Class: ThetoString()
method should be overridden to provide a meaningful string representation of theBall
object, including itscolor
andnumber
. This is essential for understanding the output of your program. -
ColorSupplier
Class: ThegetRandomColor()
method currently modifies theBall
object directly, which is not aligned with the task requirements. It should return a random color instead, allowing for better separation of concerns. -
Lottery
Class: ThegetRandomBall()
method should return aBall
object, not aString
. This is crucial for the functionality of your application. -
Application
Class: You should use a loop to create multipleBall
objects using thegetRandomBall()
method from theLottery
class, rather than creatingLottery
objects manually. This will improve code maintainability and adhere to the checklist. -
Enum Naming: Ensure that the
Colors
enum follows naming conventions, using uppercase letters for constants.
Please address these issues to ensure your code meets the task requirements. Keep up the great work, and I look forward to seeing your 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.
@@ -3,5 +3,9 @@ | |||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery[] balls = { new Lottery(), new Lottery(), new Lottery() }; |
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.
Instead of manually creating each Lottery
instance, consider using a loop to create the instances. This approach is recommended in the checklist to avoid redundancy and improve code maintainability .
public String toString() { | ||
return super.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.
The toString()
method should be overridden to provide a meaningful string representation of the Ball
object. Consider returning a string that includes both the color and number of the ball, for example: return "Ball{color=" + color + ", number=" + number + "}";
.
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
public String getRandomColor(Ball ball) { |
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 method getRandomColor
both assigns a random color to the Ball
object and returns the color. This dual responsibility might be unexpected based on the method name. Consider renaming the method to reflect its behavior more accurately, or separate the color generation and assignment into different methods.
public String getRandomBall() { | ||
Ball ball = new Ball(); | ||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
colorSupplier.getRandomColor(ball); |
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 getRandomColor
method in ColorSupplier
modifies the Ball
object directly. It might be better to have getRandomColor
return a color, which can then be set on the Ball
object here. This would improve the separation of concerns and make the code more intuitive.
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.
changed it
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.
Great job on implementing most of the task requirements! 🎉 Here are some key points to consider for improvement:
-
Application
Class: Instead of creating multipleLottery
objects, you should create a singleLottery
object and use it to generate multipleBall
objects using a loop. This will align with the task requirement to create multipleBall
objects. -
Ball
Class: Well done on overriding thetoString()
method to provide a meaningful string representation of theBall
object, including itscolor
andnumber
. -
ColorSupplier
Class: ThegetRandomColor()
method is correctly implemented, ensuring proper separation of concerns. -
Lottery
Class: ThegetRandomBall()
method is correctly implemented, returning aBall
object with a random color and number. -
Enum Naming: The
Colors
enum follows the naming conventions correctly.
The decision to approve is to help you move forward with your learning. Please review the comments to improve your code. Addressing these issues will enhance your understanding and help avoid similar problems in the future. Keep up the good work and continue learning from your experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -3,5 +3,9 @@ | |||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery[] balls = { new Lottery(), new Lottery(), new Lottery() }; |
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.
Instead of creating multiple Lottery
objects, you should create a single Lottery
object and use it to generate multiple Ball
objects using the getRandomBall()
method. This will align with the task requirement to create multiple Ball
objects.
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.
made it with for loop
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 ;)
@@ -3,5 +3,10 @@ | |||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
for (int i = 0; i < 3; i++) { |
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 3 constant field
public String getRandomColor() { | ||
return null; | ||
public Colors 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.
random should be a private final class level variable
@@ -0,0 +1,10 @@ | |||
package core.basesyntax; | |||
|
|||
public enum Colors { |
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 enum Colors { | |
public enum Color { |
import java.util.Random; | ||
|
||
public class Lottery { | ||
public Ball getRandomBall() { |
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.
Random and ColorSuplier should be a private final class level variable
public class Lottery { | ||
public Ball getRandomBall() { | ||
Ball ball = new Ball(); | ||
ColorSupplier colorSupplier = new ColorSupplier(); // Create a ColorSupplier object |
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 redundant comment
ColorSupplier colorSupplier = new ColorSupplier(); // Create a ColorSupplier object | ||
Colors randomColor = colorSupplier.getRandomColor(); | ||
ball.setColor(randomColor); | ||
int randomValue = new Random().nextInt(100); |
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 magic number constant field
|
||
public class Lottery { | ||
public Ball getRandomBall() { | ||
Ball ball = new Ball(); |
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.
also, you can create a constructor with parameters for the Ball model and simplify your solution.
No description provided.