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
8 changes: 7 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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


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

}
}
17 changes: 17 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package core.basesyntax;

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

private int number;

public Ball(String color, int number) {
this.color = color;
this.number = number;
}

@Override
public String toString() {
return "{Color: " + color + ", number: " + number + "}";
}
}
6 changes: 5 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package core.basesyntax;

import java.util.Random;

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

return Colors.values()[index].toString();
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/basesyntax/Colors.java
Original file line number Diff line number Diff line change
@@ -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 {

RED,
GREEN,
WHITE,
BLACK,
PINK,
GREY,
BLUE,
PURPLE
}
11 changes: 11 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package core.basesyntax;

import java.util.Random;

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

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

}
}
Loading