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

doneHomework #1248

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

doneHomework #1248

wants to merge 11 commits into from

Conversation

163onmyneck
Copy link

No description provided.

Copy link

@Rommelua Rommelua left a comment

Choose a reason for hiding this comment

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

Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there. The mentor will not check the work until the checklist points are corrected

Comment on lines 5 to 7
Lottery lottery1 = new Lottery();
Lottery lottery2 = new Lottery();
Lottery lottery3 = new Lottery();

Choose a reason for hiding this comment

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

Do we need 3 markets to buy 3 milk bottles?

Comment on lines 9 to 11
System.out.println(lottery1.getRandomBall());
System.out.println(lottery2.getRandomBall());
System.out.println(lottery3.getRandomBall());

Choose a reason for hiding this comment

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

Use for loop for creating several objects of the same class

Comment on lines 3 to 5
public class Ball {

private String color;

Choose a reason for hiding this comment

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

image

@163onmyneck 163onmyneck requested a review from Rommelua November 16, 2023 16:35
@@ -2,6 +2,9 @@

public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery[] lotteries = {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.

you need only one lottery here

Suggested change
Lottery[] lotteries = {new Lottery(), new Lottery(), new Lottery()};
Lottery lottery = ...;

public class ColorSupplier {
public String getRandomColor() {
return null;
int index = new Random().nextInt(Colors.values().length);

Choose a reason for hiding this comment

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

make random the class level var

@@ -0,0 +1,12 @@
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.

dont use plural form for enums

Suggested change
public enum Colors {
public enum Color {

Comment on lines 7 to 8
int randomNumber = new Random().nextInt(100);
return new Ball(new ColorSupplier().getRandomColor(), randomNumber);

Choose a reason for hiding this comment

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

make random, colorSupplier the class level vars


public class Lottery {
public Ball getRandomBall() {
int randomNumber = new Random().nextInt(100);

Choose a reason for hiding this comment

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

100 is a maggic number,
consider making it constant

@163onmyneck 163onmyneck requested a review from sokimaaa November 16, 2023 20:02
Copy link

@Rommelua Rommelua 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

Comment on lines 13 to 15
public static int getMaxNumber() {
return MAX_NUMBER;
}

Choose a reason for hiding this comment

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

Suggested change
public static int getMaxNumber() {
return MAX_NUMBER;
}

package core.basesyntax;

public class Ball {
private static final int MAX_NUMBER = 100;

Choose a reason for hiding this comment

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

move this to class Lottery

Copy link
Author

Choose a reason for hiding this comment

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

are you suggesting to delete get method for constant?

Copy link
Author

Choose a reason for hiding this comment

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

and move this constant to lottery and to not add get method for it?

@163onmyneck 163onmyneck requested a review from Rommelua November 17, 2023 11:21
Comment on lines 16 to 18
public static int getMaxNumber() {
return MAX_NUMBER;
}

Choose a reason for hiding this comment

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

You don`t need this method, just use constant

Comment on lines 11 to 12
int maxNumber = Lottery.MAX_NUMBER;
int randomNumber = random.nextInt(maxNumber);

Choose a reason for hiding this comment

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

Suggested change
int maxNumber = Lottery.MAX_NUMBER;
int randomNumber = random.nextInt(maxNumber);
int randomNumber = random.nextInt(MAX_NUMBER);

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.

4 participants