The store will not work correctly in the case when cookies are disabled.
-
Начало
-
Софтуерна програма за теглене на победители в играта "Европа Играе"
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Main {
private static final Path EMAILS_PATH = Path.of("emails that have guessed the winner.txt");
private static final Random RANDOM = new SecureRandom();
public static void main(String[] args) {
List<String> emails = readEmailsFromFile();
draw(emails, "ADIDAS PERFORMANCE Футболна топка");
draw(emails, "Ваучера за подарък на стойност от 50 лв");
}
private static List<String> readEmailsFromFile() {
try {
return new ArrayList<>(Files.readAllLines(EMAILS_PATH));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private static void draw(List<String> emails, String prize) {
for (int i = 0; i < 3; i++) {
int rand = RANDOM.nextInt(emails.size());
String winner = emails.get(rand);
System.out.printf("Поздравления! %s спечели %s!%n", winner, prize);
emails.remove(winner);
}
}
}