Java Help!
#1
I have been working on this problem for the last few weeks and not got anywhere at all. What i am trying to do is make a lottery program that stores name, tel no and 4 lottery numbers to a txt file and then when the program is run it checks 4 numbers against the ones in the txt file.
So far i have got a program to work that checks a txt file for the lowest number when only 1 number is there (not 4) and i have another program which creates 4 random numbers.
What i have so far is below:
import java.io.*;
import javax.swing.*;
public class Super7 {
private static String[] punter_name = new String [20];
private static String[] tel_number = new String [20];
private static int selection[] = new int[30][4];
private static int linecount = 0;
private static int counter = 0;
public static void main(String[] args){
String fname = JOptionPane.showInputDialog("Enter your file name/path");
System.exit(0);
}
}
public static void process(String l)
{
if (counter >= 20){
System.out.println("Arrays are full!");
return;
}
if (linecount % 3 == 0) {
punter_name[counter] = i;
}
else if (linecount % 3 == 1) {
phone_number[counter] = i;
}
else {
StringTokenizer st = new StringTokenizer(s);
int j = 0;
while (st.hasMoreTokens()) {
***** [j] = Integer.parseInt (st.NextToken());
j++;
}
}
public static int readFile(String filenm) {
int count = 0;
FileReader fileread;
String line = "xxxx";
try {
fileread = new FileReader (filenm);
}
catch (IOException e) {
errorMessage ("Error unable to open the file");
return 0;
}
BufferedReader br = new BufferedReader (fileread);
while (line != null) {
try {
line = br.readLine();
if (line != null) {
process (line);
count ++;
}
}
catch (IOException e) {
errorMessage("Error unable to read the file");
line = null;
}
}
try {
br.close();
fileread.close();
}
catch (IOException e) {
errorMessage ("Error closing file");
}
return count;
}
public static void errorMessage (String m) {
JOptionPane.showMessageDialog (null, m, "Error",
JOptionPane.ERROR_MESSAGE);
}
}
for (int index=0;index< myLottoArray.length;index++)
{
myLottoArray[index] = (int)(Math.random()*49+1);
}
for(int counter=1;counter<myLottoArray.length;counter++ )
{
for(int index=0;index< myLottoArray.length -1;index++)
{
if (myLottoArray[index] > myLottoArray[index + 1])
{
int jumble = myLottoArray[index];
myLottoArray[index]= myLottoArray[index + 1];
myLottoArray[index + 1] = jumble;
}//end if
System.out.println("The Lottery Numbers are:");
for(int index=0;index< myLottoArray.length;index++)
{
System.out.print( + myLottoArray[index] + " ");
}
}
Obviosuly its a long way off working, the code i posted is the two programs combined. If anyone could help i would be very grateful and willing to pay whatever it takes. Or if you have some good hints that would be good.
Thank you
So far i have got a program to work that checks a txt file for the lowest number when only 1 number is there (not 4) and i have another program which creates 4 random numbers.
What i have so far is below:
import java.io.*;
import javax.swing.*;
public class Super7 {
private static String[] punter_name = new String [20];
private static String[] tel_number = new String [20];
private static int selection[] = new int[30][4];
private static int linecount = 0;
private static int counter = 0;
public static void main(String[] args){
String fname = JOptionPane.showInputDialog("Enter your file name/path");
System.exit(0);
}
}
public static void process(String l)
{
if (counter >= 20){
System.out.println("Arrays are full!");
return;
}
if (linecount % 3 == 0) {
punter_name[counter] = i;
}
else if (linecount % 3 == 1) {
phone_number[counter] = i;
}
else {
StringTokenizer st = new StringTokenizer(s);
int j = 0;
while (st.hasMoreTokens()) {
***** [j] = Integer.parseInt (st.NextToken());
j++;
}
}
public static int readFile(String filenm) {
int count = 0;
FileReader fileread;
String line = "xxxx";
try {
fileread = new FileReader (filenm);
}
catch (IOException e) {
errorMessage ("Error unable to open the file");
return 0;
}
BufferedReader br = new BufferedReader (fileread);
while (line != null) {
try {
line = br.readLine();
if (line != null) {
process (line);
count ++;
}
}
catch (IOException e) {
errorMessage("Error unable to read the file");
line = null;
}
}
try {
br.close();
fileread.close();
}
catch (IOException e) {
errorMessage ("Error closing file");
}
return count;
}
public static void errorMessage (String m) {
JOptionPane.showMessageDialog (null, m, "Error",
JOptionPane.ERROR_MESSAGE);
}
}
for (int index=0;index< myLottoArray.length;index++)
{
myLottoArray[index] = (int)(Math.random()*49+1);
}
for(int counter=1;counter<myLottoArray.length;counter++ )
{
for(int index=0;index< myLottoArray.length -1;index++)
{
if (myLottoArray[index] > myLottoArray[index + 1])
{
int jumble = myLottoArray[index];
myLottoArray[index]= myLottoArray[index + 1];
myLottoArray[index + 1] = jumble;
}//end if
System.out.println("The Lottery Numbers are:");
for(int index=0;index< myLottoArray.length;index++)
{
System.out.print( + myLottoArray[index] + " ");
}
}
Obviosuly its a long way off working, the code i posted is the two programs combined. If anyone could help i would be very grateful and willing to pay whatever it takes. Or if you have some good hints that would be good.
Thank you
#3
Cheers mate, anything you can help with will be great. Im just not getting anywhere and i have to show what i have on friday.
If you can help i am willing to pay. Im not sure if what i have done so far is along the right lines.
Cheers
If you can help i am willing to pay. Im not sure if what i have done so far is along the right lines.
Cheers
#4
Scooby Regular
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes
on
0 Posts
Suppose half the troubles storing the data, im thinking linked list of the data, that way it cant be duplicated.
Reads in from file, all datas put in the linked list, then it can be added, amended etc
SI
Reads in from file, all datas put in the linked list, then it can be added, amended etc
SI
Thread
Thread Starter
Forum
Replies
Last Post