Skip to content

Commit

Permalink
Fixed OOPBasic Java Core
Browse files Browse the repository at this point in the history
  • Loading branch information
VitaliyProgrammer committed Jan 1, 2024
1 parent 98bb7f0 commit 3e32932
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 10 deletions.
7 changes: 0 additions & 7 deletions src/main/java/core/basesyntax/Application.java

This file was deleted.

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 org.example;

public class Ball {
private Color color;
private int number;

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

@Override
public String toString() {
return "Ball{" +
"color=" + color +
", number=" + number +
'}';
}
}
6 changes: 6 additions & 0 deletions src/main/java/core/basesyntax/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.example;

public enum Color {
RED, BLUE, WHITE, GREEN, ORANGE, BLACK, PURPLE
}

13 changes: 10 additions & 3 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package core.basesyntax;
package org.example;

import java.util.Random;

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

private final Color[] colors = Color.values();
private final Random random = new Random();

public Color getRandomColor() {

return colors[random.nextInt(colors.length)];
}
}
15 changes: 15 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example;

import java.util.Random;

public class Lottery {

private final ColorSupplier colorSupplier = new ColorSupplier();

private final Random random = new Random();

public Ball getRandomBall() {

return new Ball(colorSupplier.getRandomColor(), random.nextInt(100));
}
}
21 changes: 21 additions & 0 deletions src/main/java/core/basesyntax/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.example;

public class Main {
public static void main(String[] args) {

Lottery lottery = new Lottery();

for (int i = 1; i < 4; i++)
{
Ball ball = lottery.getRandomBall();
if (i == 1) {
System.out.print(i + "st ");
} else if (i == 2) {
System.out.print(i + "nd ");
} else if (i == 3) {
System.out.print(i + "rd ");
}
System.out.println(ball);
}
}
}

0 comments on commit 3e32932

Please sign in to comment.