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 #1735

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

done #1735

wants to merge 3 commits into from

Conversation

xMaXD
Copy link

@xMaXD xMaXD commented Dec 31, 2024

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

  1. Ball Class: The toString() method should be overridden to provide a meaningful string representation of the Ball object, including its color and number. This is essential for understanding the output of your program.

  2. ColorSupplier Class: The getRandomColor() method currently modifies the Ball object directly, which is not aligned with the task requirements. It should return a random color instead, allowing for better separation of concerns.

  3. Lottery Class: The getRandomBall() method should return a Ball object, not a String. This is crucial for the functionality of your application.

  4. Application Class: You should use a loop to create multiple Ball objects using the getRandomBall() method from the Lottery class, rather than creating Lottery objects manually. This will improve code maintainability and adhere to the checklist.

  5. 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() };

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 .

Comment on lines 24 to 25
public String toString() {
return super.toString();

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

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

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.

Copy link
Author

@xMaXD xMaXD left a comment

Choose a reason for hiding this comment

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

changed it

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.

Great job on implementing most of the task requirements! 🎉 Here are some key points to consider for improvement:

  • Application Class: Instead of creating multiple Lottery objects, you should create a single Lottery object and use it to generate multiple Ball objects using a loop. This will align with the task requirement to create multiple Ball objects.

  • Ball Class: Well done on overriding the toString() method to provide a meaningful string representation of the Ball object, including its color and number.

  • ColorSupplier Class: The getRandomColor() method is correctly implemented, ensuring proper separation of concerns.

  • Lottery Class: The getRandomBall() method is correctly implemented, returning a Ball 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() };

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.

Copy link
Author

@xMaXD xMaXD left a 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

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.

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

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

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 {

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 {

import java.util.Random;

public class Lottery {
public Ball getRandomBall() {

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

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

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

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.

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.

3 participants