Created
April 5, 2013 05:54
-
-
Save dasniko/5316963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jug.da.lottery; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class Lottery { | |
public static void main(String[] args) { | |
Lottery lottery = new Lottery(); | |
lottery.start(); | |
} | |
public void start() { | |
List<String> participants = getParticipants(); | |
System.out.println("Participant count: " + participants.size()); | |
Random r = new Random(); | |
int idx = r.nextInt(participants.size()); | |
System.out.println("Winner: " + participants.get(idx)); | |
} | |
private List<String> getParticipants() { | |
List<String> p = new ArrayList<String>(); | |
try { | |
@SuppressWarnings("resource") | |
BufferedReader in = new BufferedReader(new FileReader( | |
"c:\\temp\\participants.txt")); | |
String line = ""; | |
while ((line = in.readLine()) != null) { | |
p.add(line); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return p; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, ein GitHub-Projekt wäre übertrieben gewesen... :-)