What I have is an excel spreadsheet that has users First Name, Last Name, and number of times they've answered a daily trivia question correctly for the last month. What I want to do is select a winner based on a raffle system, where the users get one entry for every question they answered correctly. I have a way of doing it in Java, but I'd like to do it in excel if possible. Here is my Java code if it helps explain:
public static void main(String[] args) throws FileNotFoundException {
File file = new File("TriviaParticipantsList.txt");
Scanner scanner = new Scanner(file);
int x = 0;
int j = 0;
int i = 0;
while(scanner.hasNextLine())
{
String line = scanner.nextLine();
Scanner scan = new Scanner(line);
i = scan.nextInt();
String name = scan.nextLine();
if(line.charAt(0)==0)
{
//do nothing if no questions were answered
}
else
{
for(j=0; j<i; j++)
{
System.out.print(j+x); //Print out "ticket number"
System.out.println(" " + name); //Print out owner name of ticket
}
}
x=x+i;
}
scanner.close();
System.out.println(x); //Verify correct number of entries
int winner = (int) (Math.random()*x); //Select random number based on number of entries
System.out.println(winner); //Display value, look through list to find who number belongs to!
}
Any help is greatly appreciated!