Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

public class Application {

public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
final int NM = 3;

Choose a reason for hiding this comment

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

This violates the checklist requirement: "All magic numbers in your code should be constants." Specifically, the previous instruction also required: "The literal 3 used as the number of balls in the loop is a magic number and must be replaced with a named constant (for example, private static final int NUMBER_OF_BALLS = 3; and then use NUMBER_OF_BALLS in the for loop)." Replace final int NM = 3; with a descriptive class-level constant (e.g. private static final int NUMBER_OF_BALLS = 3;) and use it in the for loop.

Lottery lottery = new Lottery();
for (int i = 0; i < NM; i++) {
System.out.println(lottery.getRandomBall());
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package core.basesyntax;

Choose a reason for hiding this comment

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

The checklist also asks to avoid redundant empty lines around class/method signatures (see: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature."). Remove the blank line between the package statement and the public class Ball declaration so the file header and class declaration are adjacent.

public class Ball {
private final String color;
private final int number;

Choose a reason for hiding this comment

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

This violates the checklist requirement: "Remove the extra blank lines after the class declaration, before the constructor, and between the constructor and toString() as they violate the ‘no redundant empty lines after class/method signature’ checklist rule." Remove the redundant blank line before the constructor so the field declarations are followed directly by the constructor signature.

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

Choose a reason for hiding this comment

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

Redundant empty line between the constructor and the overridden method — this violates the checklist: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature." Remove the blank line.

Choose a reason for hiding this comment

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

This violates the checklist requirement: "Remove the extra blank lines after the class declaration, before the constructor, and between the constructor and toString() as they violate the ‘no redundant empty lines after class/method signature’ checklist rule." Remove the redundant blank line between the constructor and the toString() method so the constructor closing brace is followed directly by @Override and the method signature.

@Override
public String toString() {
return "Ball{"
+ "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;

Choose a reason for hiding this comment

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

There is a redundant empty line between the package and import statements. This violates the checklist: "Remove redundant empty lines: between package and import, before/after the Random field, and any trailing blank line at the end of the file so that class and method signatures are followed directly by code." Remove the empty line so import immediately follows package.


Choose a reason for hiding this comment

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

There's an extra blank line between the import and the class declaration. This also falls under the same checklist rule: "Remove redundant empty lines: between package and import, before/after the Random field, and any trailing blank line at the end of the file so that class and method signatures are followed directly by code." Remove this blank line so the class declaration directly follows the imports.

public class ColorSupplier {
private static final Random RANDOM = new Random();

Choose a reason for hiding this comment

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

The Random field is fine, but the file currently has a blank line after it. Per the checklist: "Remove redundant empty lines: between package and import, before/after the Random field, and any trailing blank line at the end of the file so that class and method signatures are followed directly by code." Remove the blank line after the field so the next method signature follows immediately.


Choose a reason for hiding this comment

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

There is an extra blank line directly after the RANDOM field. Remove this blank line so the method getRandomColor() immediately follows the field, as required by the checklist: "Remove redundant empty lines: between package and import, before/after the Random field, and any trailing blank line at the end of the file so that class and method signatures are followed directly by code."

public String getRandomColor() {
return null;
return Colors.values()[RANDOM.nextInt(Colors.values().length)].name();
Comment on lines +3 to +9

Choose a reason for hiding this comment

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

This file contains redundant empty lines. This violates the checklist item: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature." Remove the unnecessary blank lines between package/import, before/after the field declaration, and at the end of the file so the class/method signatures are directly followed by code.

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

public enum Colors {
RED,
GREEN,
BLUE,
YELLOW,
BLACK,
WHITE
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

import java.util.Random;

public class Lottery {
private static final int MX = 100;

Choose a reason for hiding this comment

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

This violates the checklist item: "Don't forget how to name constants according to style guide (the same with naming of enum values)". The constant MX is not descriptive — rename it to a clear, conventional constant name such as MAX_NUMBER or MAX_BALL_NUMBER (e.g. private static final int MAX_NUMBER = 100;).

private Random randomNumber = new Random();
private ColorSupplier colorSupplier = new ColorSupplier();
Comment on lines +7 to +8

Choose a reason for hiding this comment

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

Consider making these fields immutable to better express intent: private final Random randomNumber = new Random(); and private final ColorSupplier colorSupplier = new ColorSupplier();. This aligns with the checklist suggestion to think about which variables should be class-level and clarifies that these fields are not reassigned.


public Ball getRandomBall() {
return new Ball(colorSupplier.getRandomColor(), randomNumber.nextInt(MX + 1));
}
}