Author Topic: Java raffle script (For those of you doing raffles)  (Read 2428 times)

This may seem like it's in the wrong board, but it really needs to cater to the people running raffles here. So I think it fits.

I whipped up a raffle script in java.

RaffleDriver.java
RaffleDriver.class
Code: [Select]
// Pecon7
// 12/23/12
import java.util.*;

public class RaffleDriver
{
public static void main(String args[])
{
ArrayList<String> contestants = new ArrayList<String>();
Scanner keys = new Scanner(System.in);
System.out.println("Input contestant names until ready to start the raffle, then enter 'DRAWNAME' to remove a name. You can type 'UNDO' to remove the last name put in.");
double winPercent = 100.00;
while(true)
{
System.out.println("Enter the next contestant.");
String input = keys.nextLine();
if(input.equals("QUIT"))
break;
else if(input.equals("DRAWNAME"))
System.out.println("" + contestants.remove(RaffleDriver.getRandom(0,contestants.size()-1)) + " was drawn from the raffle!");
else if(input.equals("UNDO"))
System.out.println("Removed the last contestant: " + contestants.remove(contestants.size()-1) + "");
else
{
contestants.add(input);
winPercent = 100.0/contestants.size();
System.out.println("Added name: " + input + " | The current likelyhood of winning is " + winPercent + "%");
}
}
}

public static int getRandom(int min, int max)
{
return (int)(Math.random()*max)+min;
}
}

I don't know how to package this into a jar file. If someone could do that it would be much appreciated. Otherwise you'll need the JDK to execute this code.


Usage example:
Quote
--------------------Configuration: Raffle - JDK version 1.7.0_06 <Default> - <Default>--------------------
Input contestant names until ready to start the raffle, then enter 'DRAWNAME' to remove a name. You can type 'UNDO' to remove the last name put in.
Enter the next contestant.
Pecon7
Added name: Pecon7 | The current likelyhood of winning is 100.0%
Enter the next contestant.
Jetz
Added name: Jetz | The current likelyhood of winning is 50.0%
Enter the next contestant.
Badspot
Added name: Badspot | The current likelyhood of winning is 33.333333333333336%
Enter the next contestant.
Ephialtes
Added name: Ephialtes | The current likelyhood of winning is 25.0%
Enter the next contestant.
daf
Added name: daf | The current likelyhood of winning is 20.0%
Enter the next contestant.
UNDO
Removed the last contestant: daf
Enter the next contestant.
Shortcut
Added name: Shortcut | The current likelyhood of winning is 20.0%
Enter the next contestant.
Narkro555
Added name: Narkro555 | The current likelyhood of winning is 16.666666666666668%
Enter the next contestant.
DRAWNAME
Jetz was drawn from the raffle!
Enter the next contestant.
DRAWNAME
Pecon7 was drawn from the raffle!
Enter the next contestant.
DRAWNAME
Shortcut was drawn from the raffle!
Enter the next contestant.
« Last Edit: December 24, 2012, 04:57:31 PM by pecon98 »


You don't even need to half-understand the code to get the feel for how it works, there isn't any room in it for rigging.


Damnit pecon, I was going to write my own but I guess now there is no purpose.

I am now sad

haha u didnt get to write code

« Last Edit: December 24, 2012, 02:02:08 PM by keesfani »

Seems good, but Random.org tends to already have sufficient scripts and tools of this sort already

Damnit pecon, I was going to write my own but I guess now there is no purpose.

I am now sad
dont worry jazz you can still write some code......