Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Erica Matthews   on Sep 23 In Java Category.

  
Question Answered By: Jonah Brown   on Sep 23

Where does the data come from? Is it aready stored on
the hard drive as a txt  file or does the program  have
to let the user input it?

Here is a simplified program that reads data from a
txt file  and allows you to compare it to winning
numbers (I didn't write that part yet though). You'll
find the txt file with the customer's data after the
program:

import java.sql.*;
import java.lang.*;

public class  lotteryTest
{
public static  void main(String args[])
{
String[] custNumbers = new String[4];
try
{
//Query the data file (note: txtDsn is a text
data source that points to the directory that contains
lotteryData.txt).
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection1 =
DriverManager.getConnection("jdbc:odbc:txtDsn");
Statement statement1 =
connection1.createStatement();
String sql = "SELECT * FROM lotteryData.txt";

ResultSet rs = statement1.executeQuery(sql );
while( rs.next() )
{
for(int i = 4; i<8;i++)
{
//grab the customer's numbers  into an array
custNumbers[i-4] = rs.getString(i);
System.out.println(custNumbers[i-4]);
}
System.out.println("");
//Now all you have to do is compare the
customer's numbers to the winning numbers
//I haven't done that bit yet though, maybe
//save them in a hashmap, sort it from lowest to
highest and compare them to the winning numbers?
}
statement1.close();
connection1.close();
}
catch (Exception e)
{
System.err.println(e);
}
}
}

Here is the data file (lotteryData.txt):

FirsNm, LastNm, phone, no1, no2, no3, no4,
Fred, Bloggs, 51332555984, 12, 25, 36, 45,
Jane, Bloggs, 51332489512, 10, 15, 29, 48,

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Lottery Program Or get search suggestion and latest updates.


Tagged: