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

Final solution. #1713

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

Conversation

Wojtek-A-JAVA
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.

Your code is almost there, but there are a couple of critical issues that need to be addressed before we can approve it. 🚀 The main concern is the misuse of inheritance in the Lottery class. Instead of extending ColorSupplier, you should use composition by creating an instance of ColorSupplier within Lottery. This change will align your code with best practices and improve its design. Additionally, consider using a loop to create multiple Ball objects to reduce redundancy. Once these changes are made, your code will be in great shape! Keep up the good work! 😊

✨ 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/Application.java Outdated Show resolved Hide resolved
src/main/java/core/basesyntax/Lottery.java Outdated Show resolved Hide resolved
Copy link
Author

@Wojtek-A-JAVA Wojtek-A-JAVA left a comment

Choose a reason for hiding this comment

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

Done

Copy link

@George-Khomiak George-Khomiak left a comment

Choose a reason for hiding this comment

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

Make a few changes please, remember about access modifiers and setters/getters for your classes.

Comment on lines 4 to 5
String color;
int number;

Choose a reason for hiding this comment

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

Add access modifiers for each class field

public class ColorSupplier {
public String getRandomColor() {
return null;
public static String getRandomColor() {

Choose a reason for hiding this comment

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

From checklist: "Don't use static methods in your solution"


return randomBall;
}
}

Choose a reason for hiding this comment

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

Add empty line at the end of each files, these are not redundant

@@ -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
Ball[] ballArray = new Ball[3];
for (int i = 0; i < 3; i++) {
ballArray[i] = Lottery.getRandomBall();

Choose a reason for hiding this comment

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

When you remove "static" keyword from Lottery method "getRandomBall" you will need to create an instance of a Lottery class to use it's methods, i.e.
Lottery lottery = new Lottery();

package core.basesyntax;

public class Ball {
String color;

Choose a reason for hiding this comment

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

Add getters and setters for each class field. If you wish add a constructor to create instances of this class more easily

public class ColorSupplier {
public String getRandomColor() {
return null;
public static String getRandomColor() {

Choose a reason for hiding this comment

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

Don't convert Color to a String everywhere, just use your ENUM Color instead.

package core.basesyntax;

public class Ball {
String color;

Choose a reason for hiding this comment

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

Use Color ENUM here, not a String. So this field should be of type Color, not of a type String

BLACK,
GOLD,
SILVER
}
Copy link

@George-Khomiak George-Khomiak Dec 5, 2024

Choose a reason for hiding this comment

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

Perfect, just add a new line at the end of file :) this is our convention

@Wojtek-A-JAVA
Copy link
Author

Hi. Thank you for checking my code.
You told me to add getters and setters for color and number.
But getters are useless or should I change Lottery class for void and use getters in Application class?

@George-Khomiak
Copy link

Hi. Thank you for checking my code. You told me to add getters and setters for color and number. But getters are useless or should I change Lottery class for void and use getters in Application class?

Hi, you did well, let me explain what was off. In the class Ball you had no access modifiers for class fields - color and number - so it was possible to set these values creating a Ball class instance. But this is not the way we write code in Java, we must use access modifiers for classes, variables (class fields in this case) and functions (methods in this case). Please take a look at this topic again if you already had a lecture on it. Also ask quesions in the chat or on QA sessions.
So, when your class design is good - having access modifiers - if they are private, which is usually the case, you will not have possibility to set values for color and number without Setters. Try it. That's, mostly, the purpose of Getters/Setters.

Copy link

@George-Khomiak George-Khomiak 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 generally, now let me explain what was off. In the class Ball you had no access modifiers for class fields - color and number - so it was possible to set these values creating a Ball class instance. But this is not the way we write code in Java, we must use access modifiers for classes, variables (class fields in this case) and functions (methods in this case). Please take a look at this topic again if you already had a lecture on it. Also ask quesions in the chat or on QA sessions.
So, when your class design is good - having access modifiers - if they are private, which is usually the case, you will not have possibility to set values for color and number without Setters. Try it. That's, mostly, the purpose of Getters/Setters.

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