The Artima Developer Community
Sponsored Link

Java Answers Forum
Help comparing File info to an enterd number and out putting again

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adi

Posts: 2
Nickname: adi81
Registered: Dec, 2003

Help comparing File info to an enterd number and out putting again Posted: Dec 14, 2003 5:17 PM
Reply to this message Reply
Advertisement
this program is really starting to get the better of me mentaly.. can any one help me please ???

the idea of the program is so that it takes the info in the file wich is displayed as so

Darren Green
1234

and writes it to another file displayeing as

Darren Green 12345

then it should take the enterd users enterd number and compare it with the number read, if it matches it should print winner like so

Darren Green 12345 winner

if it only 4 numbers match it should say 4 out of 5 instead of winner and same with 3 and then two

this is the code i already have for this


/* Generated by Together */
import java.io.*;
import javax.swing.*;
public class Match {
public static void main(String[]args)
{
String [] name = new String[10];
String[] num = new String[10];
String[] ball = new String[10];

ball[0] = JOptionPane.showInputDialog("Please Enter Num");
int balls = Integer.parseInt(ball[0]);

try {
FileReader fr = new FileReader("Cust.txt");
BufferedReader inputBuffer = new BufferedReader(fr);
for (int i = 0; i < num.length; i++)
{
name = inputBuffer.readLine();
num = inputBuffer.readLine();
}
inputBuffer.close();
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog (null, "no file");
}
catch (IOException e)
{
JOptionPane.showMessageDialog (null,"Mhhee");
}

try {
FileWriter outputFile = new FileWriter("Res.text");
PrintWriter outFile = new PrintWriter (outputFile);

outFile.print(name[0]+ "\t ");
outFile.print(num[0]+ " ");
outFile.close();

}
catch (IOException e)
{ }
JOptionPane.showMessageDialog (null, "Error");
}
{
for(int y = 0; y < num.length; y++)
{
if (num[y].equals(balls))
{
try {
FileWriter outputFile = new FileWriter("Res.text", true);
PrintWriter outFile = new PrintWriter (outputFile);

outFile.print(balls + " ");
outFile.print("Winner");
outFile.close();
}
catch (IOException e)
{ }
JOptionPane.showMessageDialog (null, "Error"); //exception catches incase files are not found}
}
else
{
try {
FileWriter outputFile = new FileWriter("Res.text", true);
PrintWriter outFile = new PrintWriter (outputFile);

outFile.print(balls + " ");
outFile.print("4 out of 5");
outFile.close();
}
catch (IOException e)
{ }
JOptionPane.showMessageDialog (null, "Error"); //exception catches incase files are not found}
}


}

}
}

the other proble i have is that it is already spitting out errors with regars to the variables used in the last two try and catch stamnets and the
"for(int y = 0; y < num.length; y++)
{
if (num[y].equals(balls))"


part of the code the genneral reading and writing works but guess thats the easy part,,, aby help would be gretaly apprieciated... thanks

Topic: cougaar Previous Topic   Next Topic Topic: compilation error

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use