Java Powerball Project

Everybody know about the Powerball Lotto program. I am going to combine the fun of Java with the past Powerball winning numbers to come up with some basic statistics. I am by no means making claim to be able to predict winning Powerball Numbers. That’s just crazy. This is just for fun!

This Java program is a work in progress and this page will be updated as different statistical methods are added. Let’s start with a few basics. You pick five numbers that range between 1 and 69. You also pick red Powerball number that is between 1 and 26, ending up with six numbers for your Powerball number set.

1. Phase 1 – Define Static Variables
2. Phase 2 – Get Past Winning Numbers
3. Phase 3 – Store Past Winning Numbers
4. Phase 4 – Determine Individual Number Frequency (TBD)
5. Phase 5 – Determine Red Powerball Number Frequency (TBD)
6. Phase 6 – Determine Number Pairs Frequency (TBD)

Java Powerball Static Variables

Let’s first define some static variables that we need. We have the low and high number range for the first five numbers. Follow that with the low and high range for the Powerball number. The last two Java parms are the URL to get the past drawings list and the location to store that on my laptop.

```
//First five numbers lower/upper range
private static final int lowNumber = 1;
private static final int highNumber = 69;

//Powerball number lower/upper range
private static final int lowPBNumber = 1;
private static final int highPBNumber = 26;

//CSV file of past Powerball drawings
private static String pastDrawsFile = "C:\\Users\\Admin\\Documents\\Workspace\\powerball\\pastdraws\\winnums-text.txt";

//URL to Powerball past drawings
private static String powerBallWinnersNumbersURL = "http://www.powerball.com/powerball/winnums-text.txt";

```

Java Powerball Get Past Winning Numbers

My next task is to create a method that will go out and get the Powerball past winnings file and store it locally to my laptop. This method

```public static void getPastWinningsFile(String powerBallWinnersNumbersURL, String pastDrawsFile)
{
StringBuffer stringBuffer = new StringBuffer();

try
{
URL url = new URL(powerBallWinnersNumbersURL);

while (contentLine != null)
{
stringBuffer.append("\n"+contentLine);
}

//Write the contents of file URL to local file
FileWriter fileWriter = new FileWriter(pastDrawsFile, false);

//Write the data
fileWriter.write(stringBuffer.toString());

//Close the handle
fileWriter.close();

}
catch(Exception ex)
{
System.out.println("Exception:"+ex.toString());
}

}
```

Java Powerball Store Past Winning Numbers

```public static void storePastWinningsNumbers()
{

String eachLine = "";
String lastDate = "";
ArrayList<String> numberSets = new ArrayList<String>();
ArrayList<Integer> pbNumbers = new ArrayList<Integer>();

try
{

{

//Ignore all the lines that are not number sets
if(eachLine.length() < 10) {
continue;
}

//Split the line by space
String splitLine[] = eachLine.split("  ");

//Add all six numbers to ArrayList
numberSets.add(splitLine[1]+" "+splitLine[2]+" "+splitLine[3]+" "+splitLine[4]+" "+splitLine[5]+" "+splitLine[6]);

//Add just the sixth number (Powerball) to an ArrayList

//Capture the date of the earliest winning number set
lastDate = splitLine[0];
}

//Set the earliest date of drawing
earliestDate = lastDate;

//Store the number of sets
sampleSize = numberSets.size();

}
catch(Exception ex)
{
System.out.println("Exception:"+ex.toString());
}
}
```

Java Powerball Individual Number Frequency

Java method to determine which numbers (first five) are drawn the most often. This Java method will be coming soon.

Java Powerball Red Powerball Number Frequency

Java method to determine which of the Red Powerball number (sixth number) is drawn most often. This Java method will be coming soon.

Java Powerball Number Pairs Frequency

Java method to determine which pairs of numbers are most often drawn together. This Java method will be coming soon.

Java References:

One Comment