import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class SchoolLotteryFromFile{
	private ArrayList<String> entries;	// holds Student references
	public SchoolLotteryFromFile(){
		entries = new ArrayList<>();
	}

	public void addStudents(String name){
		if(entries.contains(name)) {
			System.out.println("Duplicate Detected!, You think you're so smart? "+name);
			return;
		}
		System.out.println(name + " entered in the lottery.");
		entries.add(name);
	}

	public void pickWinner(){
		// chooses a random entry and displays winners name
		int numEntries = entries.size();	// size of ArrayList
		if(numEntries == 0)
			System.out.println("*** No participants ***");
		else{
			Random random = new Random();
			String winner = entries.get(random.nextInt(numEntries));
			System.out.print("\n*** The winner is " + winner + " ***");
		}
	}

	public static void main(String[] args){
		SchoolLotteryFromFile lottery = new SchoolLotteryFromFile();
		Scanner sc;
		try {
			sc = new Scanner(new File("studentList.txt"));
			while(sc.hasNextLine())lottery.addStudents(sc.nextLine());
			lottery.pickWinner();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
	}
}