From 9d740599dc1f983928fe702d4eef8ea5977c0bf0 Mon Sep 17 00:00:00 2001 From: Anna Simko <108935534+Ann1120-ua@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:40:57 -0500 Subject: [PATCH] fixed some mistakes 5 --- src/main/java/core/basesyntax/Application.java | 6 +++--- src/main/java/core/basesyntax/Ball.java | 4 ++-- src/main/java/core/basesyntax/ColorSupplier.java | 10 ++++------ src/main/java/core/basesyntax/Lottery.java | 10 +++++----- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java index 1a008913b..d714a6655 100644 --- a/src/main/java/core/basesyntax/Application.java +++ b/src/main/java/core/basesyntax/Application.java @@ -1,13 +1,13 @@ package core.basesyntax; public class Application { + private static final int NUMBER_OF_BALLS = 3; + public static void main(String[] args) { Lottery lottery = new Lottery(); - final int numberOfBalls = 3; - - for (int i = 0; i < numberOfBalls; i++) { + for (int i = 0; i < NUMBER_OF_BALLS; i++) { Ball ball = lottery.getRandomBall(); System.out.println(ball); } diff --git a/src/main/java/core/basesyntax/Ball.java b/src/main/java/core/basesyntax/Ball.java index dcc259b67..3ad453e68 100644 --- a/src/main/java/core/basesyntax/Ball.java +++ b/src/main/java/core/basesyntax/Ball.java @@ -4,8 +4,8 @@ public class Ball { private final Color color; private final int number; - public Ball(String color, int number) { - this.color = Color.valueOf(color); + public Ball(Color color, int number) { + this.color = color; this.number = number; } diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index 25db20973..0cf5d0201 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -3,13 +3,11 @@ import java.util.Random; public class ColorSupplier { - private Random random = new Random(); - - public String getRandomColor() { + private final Random random = new Random(); + public Color getRandomColor() { Color[] colors = Color.values(); - int randomIndex = random.nextInt(colors.length); - - return colors[randomIndex].name(); + int index = random.nextInt(colors.length); + return colors[index]; } } diff --git a/src/main/java/core/basesyntax/Lottery.java b/src/main/java/core/basesyntax/Lottery.java index 315161f63..f9e698c01 100644 --- a/src/main/java/core/basesyntax/Lottery.java +++ b/src/main/java/core/basesyntax/Lottery.java @@ -4,13 +4,13 @@ public class Lottery { - private final int maxBallCount = 100; - private Random random = new Random(); - private ColorSupplier colorSupplier = new ColorSupplier(); + private final static int MAX_BALL_COUNT = 100; + private final Random random = new Random(); + private final ColorSupplier colorSupplier = new ColorSupplier(); public Ball getRandomBall() { - String color = colorSupplier.getRandomColor(); - int number = random.nextInt(maxBallCount) + 1; + Color color = colorSupplier.getRandomColor(); + int number = random.nextInt(MAX_BALL_COUNT) + 1; return new Ball(color, number); } }