Java Beginners

Moderators: zibadian
Number of threads: 1233
Number of posts: 2675

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 13 Jul 2007 at 9:23 PM
Hi everyone. I'm new to Java and programming in general. I'm trying to write a file parsing program that takes a report saved in one text doc and pulls out the need information saving it to another text doc. Basically it removes the unneeded information and puts it in format that is easy to import to say a database. It was working fine until I added in the last piece that process the individual lines of data. The program will now compile in a class doc but nothing is outputted to the output doc. Before this happened I was able to pull other parts that I wanted and have it output to the new file correctly. I'm trying to produce a report that looks like this:

Rundate ASC Loan DelqM - header
6/1/07 036 123456789 Y - data

The file to parse looks like this:

Report: Fake Report for Fake Loans
Report ID: 000001
Run Date: 04/25/2007
----------------------------------------------------------------------
ASC Number Loan ID DelqMessage
033 000101000 N
034 001234875 Y
035 123456789 N

----------------------------------------------------------------------
ASC Number Loan ID DelqMessage
036 741258963 N
037 872563987 N
038 987521455 Y

======================================================================

Fake Report Summary:
ASC Total: 6
Loan Total: 6
Total Delq: 2

The following is the code I have so far:

import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;

public class ParseFile {
    public static void main(String[] args) throws IOException {
        
	// Variable Declaration
	 
	boolean procOn;
	String RunDate = "";
	BufferedReader inputStream = null;
        PrintWriter outputStream = null;
	
	//  Following block of code parses FakeReportToParse.txt and outputs
	//  needed portions of the report to characteroutput.txt
	 
        try {
		
	   procOn=false;
	   
	    inputStream = 
                new BufferedReader(new FileReader("FakeReportToParse.txt"));
            outputStream = 
                new PrintWriter(new FileWriter("characteroutput.txt"));

            String l;
            while ((l = inputStream.readLine()) != null) {
		    
	    outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
	       
	       if (l.indexOf("Run Date:")>=0) {
		RunDate = l.substring(10);
		outputStream.println(RunDate);
	    }  
	    
	    // Processing of report data
	    
	    if(l.indexOf("ASC Number      Loan ID") >= 0) {
		    procOn = true;
	    }
	    
	    if(l.indexOf("-----------") >= 0 || l.indexOf("===========") >= 0) { 
		    procOn = false;
	    }
		
	     if(l.indexOf("") >= 0) {
		     procOn = false;
		}
	    	    
	    // Output report data to new characteroutput.txt file

	    if(procOn) {
		    String ASC = l.substring(0, 4).trim();
		    String LoanID = l.substring(15, 25).trim();
		    String DelqM = l.substring(30).trim();
	
	outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
	
	    }
	    }
	}
	catch(Exception z){
            System.out.println("Error: " + z.toString());
	    }
}
}


Any help would be appreciate as I'm stuck as to what is wrong.

Thanks
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 13 Jul 2007 at 9:55 PM
: Hi everyone. I'm new to Java and programming in general. I'm trying
: to write a file parsing program that takes a report saved in one
: text doc and pulls out the need information saving it to another
: text doc. Basically it removes the unneeded information and puts it
: in format that is easy to import to say a database. It was working
: fine until I added in the last piece that process the individual
: lines of data. The program will now compile in a class doc but
: nothing is outputted to the output doc. Before this happened I was
: able to pull other parts that I wanted and have it output to the new
: file correctly. I'm trying to produce a report that looks like this:
:
: Rundate ASC Loan DelqM - header
: 6/1/07 036 123456789 Y - data
:
: The file to parse looks like this:
:
: Report: Fake Report for Fake Loans
: Report ID: 000001
: Run Date: 04/25/2007
: ---------------------------------------------------------------------
: -
: ASC Number Loan ID DelqMessage
: 033 000101000 N
: 034 001234875 Y
: 035 123456789 N
:
: ---------------------------------------------------------------------
: -
: ASC Number Loan ID DelqMessage
: 036 741258963 N
: 037 872563987 N
: 038 987521455 Y
:
: =====================================================================
: =
:
: Fake Report Summary:
: ASC Total: 6
: Loan Total: 6
: Total Delq: 2
:
: The following is the code I have so far:
:
:
: 
: import java.io.FileReader;
: import java.io.FileWriter;
: import java.io.BufferedReader;
: import java.io.PrintWriter;
: import java.io.IOException;
: 
: public class ParseFile {
:     public static void main(String[] args) throws IOException {
:         
: 	// Variable Declaration
: 	 
: 	boolean procOn;
: 	String RunDate = "";
: 	BufferedReader inputStream = null;
:         PrintWriter outputStream = null;
: 	
: 	//  Following block of code parses FakeReportToParse.txt and outputs
: 	//  needed portions of the report to characteroutput.txt
: 	 
:         try {
: 		
: 	   procOn=false;
: 	   
: 	    inputStream = 
:                 new BufferedReader(new FileReader("FakeReportToParse.txt"));
:             outputStream = 
:                 new PrintWriter(new FileWriter("characteroutput.txt"));
: 
:             String l;
:             while ((l = inputStream.readLine()) != null) {
: 		    
: 	    outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
: 	       
: 	       if (l.indexOf("Run Date:")>=0) {
: 		RunDate = l.substring(10);
: 		outputStream.println(RunDate);
: 	    }  
: 	    
: 	    // Processing of report data
: 	    
: 	    if(l.indexOf("ASC Number      Loan ID") >= 0) {
: 		    procOn = true;
: 	    }
: 	    
: 	    if(l.indexOf("-----------") >= 0 || l.indexOf("===========") >= 0) { 
: 		    procOn = false;
: 	    }
: 		
: 	     if(l.indexOf("") >= 0) {
: 		     procOn = false;
: 		}
: 	    	    
: 	    // Output report data to new characteroutput.txt file
: 
: 	    if(procOn) {
: 		    String ASC = l.substring(0, 4).trim();
: 		    String LoanID = l.substring(15, 25).trim();
: 		    String DelqM = l.substring(30).trim();
: 	
: 	outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
: 	
: 	    }
: 	    }
: 	}
: 	catch(Exception z){
:             System.out.println("Error: " + z.toString());
: 	    }
: }
: }
: 
:
:
: Any help would be appreciate as I'm stuck as to what is wrong.
:
: Thanks
:
You forgot to close() the streams. Only when you close them, will the data be flushed to the storage medium.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 14 Jul 2007 at 1:43 PM
: You forgot to close() the streams. Only when you close them, will
: the data be flushed to the storage medium.

I added the following piece of code within a finally to resolve the closing of the outputstream/inputstream.

 finally {
		if (inputStream != null) {
			inputStream.close();
		}
		if (outputStream != null) {
			outputStream.close();
		}
    }


This has partly resolved my prior issue. I now get part of the expected output as the header info is outputted as well as one instance of the 4/25/07 run date. However, none of the lines of data are being outputted. Any hints as to what I may be doing wrong here.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 14 Jul 2007 at 2:04 PM
: : You forgot to close() the streams. Only when you close them, will
: : the data be flushed to the storage medium.
:
: I added the following piece of code within a finally to resolve the
: closing of the outputstream/inputstream.
:
:
: 
:  finally {
: 		if (inputStream != null) {
: 			inputStream.close();
: 		}
: 		if (outputStream != null) {
: 			outputStream.close();
: 		}
:     }
: 
:
:
: This has partly resolved my prior issue. I now get part of the
: expected output as the header info is outputted as well as one
: instance of the 4/25/07 run date. However, none of the lines of data
: are being outputted. Any hints as to what I may be doing wrong here.
:
This part of your code seems to be the problem:
: 	     if(l.indexOf("") >= 0) {
: 		     procOn = false;
: 		}

This checks if the string l has an empty part in it, which is always true. If you want to check whether 2 strings are equal, then you need to use the String.equals() method.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 14 Jul 2007 at 2:13 PM
: : : You forgot to close() the streams. Only when you close them, will
: : : the data be flushed to the storage medium.
: :
: : I added the following piece of code within a finally to resolve the
: : closing of the outputstream/inputstream.
: :
: :
: : 
: :  finally {
: : 		if (inputStream != null) {
: : 			inputStream.close();
: : 		}
: : 		if (outputStream != null) {
: : 			outputStream.close();
: : 		}
: :     }
: : 
: :
: :
: : This has partly resolved my prior issue. I now get part of the
: : expected output as the header info is outputted as well as one
: : instance of the 4/25/07 run date. However, none of the lines of data
: : are being outputted. Any hints as to what I may be doing wrong here.
: :
: This part of your code seems to be the problem:
:
: 
: : 	     if(l.indexOf("") >= 0) {
: : 		     procOn = false;
: : 		}
: 
:
: This checks if the string l has an empty part in it, which is always
: true. If you want to check whether 2 strings are equal, then you
: need to use the String.equals() method.

Thanks that code is there to check if the line is blank. I was getting an error message within the procOn part because there is a blank line between the last line of data and the symbols I was using to end it so that the series of ===== is not outputted. What I'm looking to do is turn procOn to false if the entire line is blank. Is there a way to say if line is completely blank do this? Such a certain class, etc I should look into that might resolve for me?
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 14 Jul 2007 at 10:52 PM
: : : : You forgot to close() the streams. Only when you close them, will
: : : : the data be flushed to the storage medium.
: : :
: : : I added the following piece of code within a finally to resolve the
: : : closing of the outputstream/inputstream.
: : :
: : :
: : : 
: : :  finally {
: : : 		if (inputStream != null) {
: : : 			inputStream.close();
: : : 		}
: : : 		if (outputStream != null) {
: : : 			outputStream.close();
: : : 		}
: : :     }
: : : 
: : :
: : :
: : : This has partly resolved my prior issue. I now get part of the
: : : expected output as the header info is outputted as well as one
: : : instance of the 4/25/07 run date. However, none of the lines of data
: : : are being outputted. Any hints as to what I may be doing wrong here.
: : :
: : This part of your code seems to be the problem:
: :
: : 
: : : 	     if(l.indexOf("") >= 0) {
: : : 		     procOn = false;
: : : 		}
: : 
: :
: : This checks if the string l has an empty part in it, which is always
: : true. If you want to check whether 2 strings are equal, then you
: : need to use the String.equals() method.

:
: Thanks that code is there to check if the line is blank. I was
: getting an error message within the procOn part because there is a
: blank line between the last line of data and the symbols I was using
: to end it so that the series of ===== is not outputted. What I'm
: looking to do is turn procOn to false if the entire line is blank.
: Is there a way to say if line is completely blank do this? Such a
: certain class, etc I should look into that might resolve for me?
:
If you look at my previous reply, you'll see the answer. To check if a string is equal to an empry string use the String.equals() method. For more info see: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#equals(java.lang.Object)
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 17 Jul 2007 at 7:47 PM
I've been able to resolve the blank line issue, however, when the data outputs the line reading "ASC Number Loan ID DelqMessage" first. This causes the output to read like:

Rundate ASC Loan Delq Message
4/25/07 ASC LoanID elqMessage
4/25/07 033 0001010000 N

I do not want that 1st line to output with the ASC LoanID elqMessage. I created an array that is suppose to process all of the junk lines, ie report lines I do not want in th final output. However, I continue to get the following errors:

FileParse.java:91: cannot find symbol
symbol : variable junkRow
location: class FileParse
for(int i = 0; i < junkRow.length();i++) {
^
FileParse.java:92: cannot find symbol
symbol : variable junkRow
location: class FileParse
if(x.indexOf(junkRow[i])) {
^

Here is what I have coded which should be correct:

import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;

public class FileParse {
    public void main(String[] args) throws IOException {
         
    	// Variable Declaration
	
	boolean procOn;
	String RunDate = "";
	BufferedReader inputStream = null;
	PrintWriter outputStream = null;
	String [] junkRow;
	junkRow = new String[6];
	
	// Following initializes elements of array
	
	junkRow[0] = "Report";
	junkRow[1] = "ASC Number";
	junkRow[2] = "Fake Report";
	junkRow[3] = "Loan Total";
	junkRow[4] = "Total Delq";
	junkRow[5] = "ASC Total";
			
	// Following block of cod parses FakeReportToParse.txt and outputs
	// needed portions of the report to characteroutput.txt
	
	try {
	
	 procOn = false;
	   
	   inputStream = 
	   	new BufferedReader(new FileReader("FakeReportToParse.txt"));
	   outputStream = 
	   	new PrintWriter(new FileWriter("characteroutput.txt"));
		
		outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");

	   String l;
	   while ((l = inputStream.readLine()) != null) {
	   
	   	  if (l.indexOf("Run Date:") >= 0) {
		  RunDate = l.substring(10);
		  }
		
		  // Processing of report data
		  
		  if(l.indexOf("ASC Number") >= 0) {
			  procOn = true;
		  }
		  
		  if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
			 procOn = false;
			 }
		
		// Output report data to new characteroutput.txt file
		
		 if(procOn) {
		
			if(!isjunk(l)) {
	      		String ASC = l.substring(0, 4).trim();
			String LoanID = l.substring(15, 25).trim();
			String DelqM = l.substring(30).trim();
		
			{
     outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
			}
			 }
     }
     }
	} catch(Exception z){
            System.out.println("Error: " + z.toString());
	    }
	    
     finally {
		if (inputStream != null) {
			inputStream.close();
		}
		if (outputStream != null) {
			outputStream.close();
		}
    }
	}
// @return true if it's a junk row
// @return false if it's not

private boolean isjunk(String x){
	for(int i = 0; i < junkRow.length();i++){
	if(x.indexOf(junkRow[i])){
		return true;
		}
		if(x.trim().length() < 1) {
			  return true;
		  }
	} return false;
}
}


Any help would be appreciated.

Thanks
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 17 Jul 2007 at 8:25 PM
: I've been able to resolve the blank line issue, however, when the
: data outputs the line reading "ASC Number Loan ID
: DelqMessage" first. This causes the output to read like:
:
: Rundate ASC Loan Delq Message
: 4/25/07 ASC LoanID elqMessage
: 4/25/07 033 0001010000 N
:
: I do not want that 1st line to output with the ASC LoanID
: elqMessage. I created an array that is suppose to process all of the
: junk lines, ie report lines I do not want in th final output.
: However, I continue to get the following errors:
:
: FileParse.java:91: cannot find symbol
: symbol : variable junkRow
: location: class FileParse
: for(int i = 0; i < junkRow.length();i++) {
: ^
: FileParse.java:92: cannot find symbol
: symbol : variable junkRow
: location: class FileParse
: if(x.indexOf(junkRow[i])) {
: ^
:
: Here is what I have coded which should be correct:
:
:
: 
: import java.io.FileReader;
: import java.io.FileWriter;
: import java.io.BufferedReader;
: import java.io.PrintWriter;
: import java.io.IOException;
: 
: public class FileParse {
:     public void main(String[] args) throws IOException {
:          
:     	// Variable Declaration
: 	
: 	boolean procOn;
: 	String RunDate = "";
: 	BufferedReader inputStream = null;
: 	PrintWriter outputStream = null;
: 	String [] junkRow;
: 	junkRow = new String[6];
: 	
: 	// Following initializes elements of array
: 	
: 	junkRow[0] = "Report";
: 	junkRow[1] = "ASC Number";
: 	junkRow[2] = "Fake Report";
: 	junkRow[3] = "Loan Total";
: 	junkRow[4] = "Total Delq";
: 	junkRow[5] = "ASC Total";
: 			
: 	// Following block of cod parses FakeReportToParse.txt and outputs
: 	// needed portions of the report to characteroutput.txt
: 	
: 	try {
: 	
: 	 procOn = false;
: 	   
: 	   inputStream = 
: 	   	new BufferedReader(new FileReader("FakeReportToParse.txt"));
: 	   outputStream = 
: 	   	new PrintWriter(new FileWriter("characteroutput.txt"));
: 		
: 		outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
: 
: 	   String l;
: 	   while ((l = inputStream.readLine()) != null) {
: 	   
: 	   	  if (l.indexOf("Run Date:") >= 0) {
: 		  RunDate = l.substring(10);
: 		  }
: 		
: 		  // Processing of report data
: 		  
: 		  if(l.indexOf("ASC Number") >= 0) {
: 			  procOn = true;
: 		  }
: 		  
: 		  if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
: 			 procOn = false;
: 			 }
: 		
: 		// Output report data to new characteroutput.txt file
: 		
: 		 if(procOn) {
: 		
: 			if(!isjunk(l)) {
: 	      		String ASC = l.substring(0, 4).trim();
: 			String LoanID = l.substring(15, 25).trim();
: 			String DelqM = l.substring(30).trim();
: 		
: 			{
:      outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
: 			}
: 			 }
:      }
:      }
: 	} catch(Exception z){
:             System.out.println("Error: " + z.toString());
: 	    }
: 	    
:      finally {
: 		if (inputStream != null) {
: 			inputStream.close();
: 		}
: 		if (outputStream != null) {
: 			outputStream.close();
: 		}
:     }
: 	}
: // @return true if it's a junk row
: // @return false if it's not
: 
: private boolean isjunk(String x){
: 	for(int i = 0; i < junkRow.length();i++){
: 	if(x.indexOf(junkRow[i])){
: 		return true;
: 		}
: 		if(x.trim().length() < 1) {
: 			  return true;
: 		  }
: 	} return false;
: }
: }
: 
:
:
: Any help would be appreciated.
:
: Thanks
:
You've defined junkRow as a local variable in main(), which means that you can only use it in that method. To use it in other methods, you'll need to pass it as a method parameter, or define it as a class field.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 20 Jul 2007 at 8:38 PM
: : I've been able to resolve the blank line issue, however, when the
: : data outputs the line reading "ASC Number Loan ID
: : DelqMessage" first. This causes the output to read like:
: :
: : Rundate ASC Loan Delq Message
: : 4/25/07 ASC LoanID elqMessage
: : 4/25/07 033 0001010000 N
: :
: : I do not want that 1st line to output with the ASC LoanID
: : elqMessage. I created an array that is suppose to process all of the
: : junk lines, ie report lines I do not want in th final output.
: : However, I continue to get the following errors:
: :
: : FileParse.java:91: cannot find symbol
: : symbol : variable junkRow
: : location: class FileParse
: : for(int i = 0; i < junkRow.length();i++) {
: : ^
: : FileParse.java:92: cannot find symbol
: : symbol : variable junkRow
: : location: class FileParse
: : if(x.indexOf(junkRow[i])) {
: : ^
: :
: : Here is what I have coded which should be correct:
: :
: :
: : 
: : import java.io.FileReader;
: : import java.io.FileWriter;
: : import java.io.BufferedReader;
: : import java.io.PrintWriter;
: : import java.io.IOException;
: : 
: : public class FileParse {
: :     public void main(String[] args) throws IOException {
: :          
: :     	// Variable Declaration
: : 	
: : 	boolean procOn;
: : 	String RunDate = "";
: : 	BufferedReader inputStream = null;
: : 	PrintWriter outputStream = null;
: : 	String [] junkRow;
: : 	junkRow = new String[6];
: : 	
: : 	// Following initializes elements of array
: : 	
: : 	junkRow[0] = "Report";
: : 	junkRow[1] = "ASC Number";
: : 	junkRow[2] = "Fake Report";
: : 	junkRow[3] = "Loan Total";
: : 	junkRow[4] = "Total Delq";
: : 	junkRow[5] = "ASC Total";
: : 			
: : 	// Following block of cod parses FakeReportToParse.txt and outputs
: : 	// needed portions of the report to characteroutput.txt
: : 	
: : 	try {
: : 	
: : 	 procOn = false;
: : 	   
: : 	   inputStream = 
: : 	   	new BufferedReader(new FileReader("FakeReportToParse.txt"));
: : 	   outputStream = 
: : 	   	new PrintWriter(new FileWriter("characteroutput.txt"));
: : 		
: : 		outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
: : 
: : 	   String l;
: : 	   while ((l = inputStream.readLine()) != null) {
: : 	   
: : 	   	  if (l.indexOf("Run Date:") >= 0) {
: : 		  RunDate = l.substring(10);
: : 		  }
: : 		
: : 		  // Processing of report data
: : 		  
: : 		  if(l.indexOf("ASC Number") >= 0) {
: : 			  procOn = true;
: : 		  }
: : 		  
: : 		  if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
: : 			 procOn = false;
: : 			 }
: : 		
: : 		// Output report data to new characteroutput.txt file
: : 		
: : 		 if(procOn) {
: : 		
: : 			if(!isjunk(l)) {
: : 	      		String ASC = l.substring(0, 4).trim();
: : 			String LoanID = l.substring(15, 25).trim();
: : 			String DelqM = l.substring(30).trim();
: : 		
: : 			{
: :      outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
: : 			}
: : 			 }
: :      }
: :      }
: : 	} catch(Exception z){
: :             System.out.println("Error: " + z.toString());
: : 	    }
: : 	    
: :      finally {
: : 		if (inputStream != null) {
: : 			inputStream.close();
: : 		}
: : 		if (outputStream != null) {
: : 			outputStream.close();
: : 		}
: :     }
: : 	}
: : // @return true if it's a junk row
: : // @return false if it's not
: : 
: : private boolean isjunk(String x){
: : 	for(int i = 0; i < junkRow.length();i++){
: : 	if(x.indexOf(junkRow[i])){
: : 		return true;
: : 		}
: : 		if(x.trim().length() < 1) {
: : 			  return true;
: : 		  }
: : 	} return false;
: : }
: : }
: : 
: :
: :
: : Any help would be appreciated.
: :
: : Thanks
: :
: You've defined junkRow as a local variable in main(), which means
: that you can only use it in that method. To use it in other methods,
: you'll need to pass it as a method parameter, or define it as a
: class field.

I have been trying to figure out how to pass it as a method parameter or define it as a class field without success. I have tried to do it but cannot even through I have read up on it. Would be able to show me how to do it so I can learn about it or provide me an example?

I really do appreciate all of your help.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 20 Jul 2007 at 11:41 PM
: I've been able to resolve the blank line issue, however, when the
: data outputs the line reading "ASC Number Loan ID
: DelqMessage" first. This causes the output to read like:
:
: Rundate ASC Loan Delq Message
: 4/25/07 ASC LoanID elqMessage
: 4/25/07 033 0001010000 N
:
: I do not want that 1st line to output with the ASC LoanID
: elqMessage. I created an array that is suppose to process all of the
: junk lines, ie report lines I do not want in th final output.
: However, I continue to get the following errors:
:
: FileParse.java:91: cannot find symbol
: symbol : variable junkRow
: location: class FileParse
: for(int i = 0; i < junkRow.length();i++) {
: ^
: FileParse.java:92: cannot find symbol
: symbol : variable junkRow
: location: class FileParse
: if(x.indexOf(junkRow[i])) {
: ^
:
: Here is what I have coded which should be correct:
:
:
: 
: import java.io.FileReader;
: import java.io.FileWriter;
: import java.io.BufferedReader;
: import java.io.PrintWriter;
: import java.io.IOException;
: 
: public class FileParse {
:     public void main(String[] args) throws IOException {
:          
:     	// Variable Declaration
: 	
: 	boolean procOn;
: 	String RunDate = "";
: 	BufferedReader inputStream = null;
: 	PrintWriter outputStream = null;
: 	String [] junkRow;
: 	junkRow = new String[6];
: 	
: 	// Following initializes elements of array
: 	
: 	junkRow[0] = "Report";
: 	junkRow[1] = "ASC Number";
: 	junkRow[2] = "Fake Report";
: 	junkRow[3] = "Loan Total";
: 	junkRow[4] = "Total Delq";
: 	junkRow[5] = "ASC Total";
: 			
: 	// Following block of cod parses FakeReportToParse.txt and outputs
: 	// needed portions of the report to characteroutput.txt
: 	
: 	try {
: 	
: 	 procOn = false;
: 	   
: 	   inputStream = 
: 	   	new BufferedReader(new FileReader("FakeReportToParse.txt"));
: 	   outputStream = 
: 	   	new PrintWriter(new FileWriter("characteroutput.txt"));
: 		
: 		outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
: 
: 	   String l;
: 	   while ((l = inputStream.readLine()) != null) {
: 	   
: 	   	  if (l.indexOf("Run Date:") >= 0) {
: 		  RunDate = l.substring(10);
: 		  }
: 		
: 		  // Processing of report data
: 		  
: 		  if(l.indexOf("ASC Number") >= 0) {
: 			  procOn = true;
: 		  }
: 		  
: 		  if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
: 			 procOn = false;
: 			 }
: 		
: 		// Output report data to new characteroutput.txt file
: 		
: 		 if(procOn) {
: 		
: 			if(!isjunk(l)) {
: 	      		String ASC = l.substring(0, 4).trim();
: 			String LoanID = l.substring(15, 25).trim();
: 			String DelqM = l.substring(30).trim();
: 		
: 			{
:      outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
: 			}
: 			 }
:      }
:      }
: 	} catch(Exception z){
:             System.out.println("Error: " + z.toString());
: 	    }
: 	    
:      finally {
: 		if (inputStream != null) {
: 			inputStream.close();
: 		}
: 		if (outputStream != null) {
: 			outputStream.close();
: 		}
:     }
: 	}
: // @return true if it's a junk row
: // @return false if it's not
: 
: private boolean isjunk(String x){
: 	for(int i = 0; i < junkRow.length();i++){
: 	if(x.indexOf(junkRow[i])){
: 		return true;
: 		}
: 		if(x.trim().length() < 1) {
: 			  return true;
: 		  }
: 	} return false;
: }
: }
: 
:
:
: Any help would be appreciated.
:
: Thanks
:
Change isJunk() to:
private boolean isjunk(String x, String[] junkRow)

and then add the junkRow to the parameters. Example:
  isjunk(someString, junkRow)


To make it a class field move the junkRow definition to between the main() and the line containing the class definition:
public class FileParse {

    private static String[] junkRow;

    public void main(String[] args) throws IOException {

because there is no object instance of FileParse, you need to make junkRow static. The word private means that other classes cannot use it (see variable scopes for more info).
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 21 Jul 2007 at 12:51 PM
: : I've been able to resolve the blank line issue, however, when the
: : data outputs the line reading "ASC Number Loan ID
: : DelqMessage" first. This causes the output to read like:
: :
: : Rundate ASC Loan Delq Message
: : 4/25/07 ASC LoanID elqMessage
: : 4/25/07 033 0001010000 N
: :
: : I do not want that 1st line to output with the ASC LoanID
: : elqMessage. I created an array that is suppose to process all of the
: : junk lines, ie report lines I do not want in th final output.
: : However, I continue to get the following errors:
: :
: : FileParse.java:91: cannot find symbol
: : symbol : variable junkRow
: : location: class FileParse
: : for(int i = 0; i < junkRow.length();i++) {
: : ^
: : FileParse.java:92: cannot find symbol
: : symbol : variable junkRow
: : location: class FileParse
: : if(x.indexOf(junkRow[i])) {
: : ^
: :
: : Here is what I have coded which should be correct:
: :
: :
: : 
: : import java.io.FileReader;
: : import java.io.FileWriter;
: : import java.io.BufferedReader;
: : import java.io.PrintWriter;
: : import java.io.IOException;
: : 
: : public class FileParse {
: :     public void main(String[] args) throws IOException {
: :          
: :     	// Variable Declaration
: : 	
: : 	boolean procOn;
: : 	String RunDate = "";
: : 	BufferedReader inputStream = null;
: : 	PrintWriter outputStream = null;
: : 	String [] junkRow;
: : 	junkRow = new String[6];
: : 	
: : 	// Following initializes elements of array
: : 	
: : 	junkRow[0] = "Report";
: : 	junkRow[1] = "ASC Number";
: : 	junkRow[2] = "Fake Report";
: : 	junkRow[3] = "Loan Total";
: : 	junkRow[4] = "Total Delq";
: : 	junkRow[5] = "ASC Total";
: : 			
: : 	// Following block of cod parses FakeReportToParse.txt and outputs
: : 	// needed portions of the report to characteroutput.txt
: : 	
: : 	try {
: : 	
: : 	 procOn = false;
: : 	   
: : 	   inputStream = 
: : 	   	new BufferedReader(new FileReader("FakeReportToParse.txt"));
: : 	   outputStream = 
: : 	   	new PrintWriter(new FileWriter("characteroutput.txt"));
: : 		
: : 		outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
: : 
: : 	   String l;
: : 	   while ((l = inputStream.readLine()) != null) {
: : 	   
: : 	   	  if (l.indexOf("Run Date:") >= 0) {
: : 		  RunDate = l.substring(10);
: : 		  }
: : 		
: : 		  // Processing of report data
: : 		  
: : 		  if(l.indexOf("ASC Number") >= 0) {
: : 			  procOn = true;
: : 		  }
: : 		  
: : 		  if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
: : 			 procOn = false;
: : 			 }
: : 		
: : 		// Output report data to new characteroutput.txt file
: : 		
: : 		 if(procOn) {
: : 		
: : 			if(!isjunk(l)) {
: : 	      		String ASC = l.substring(0, 4).trim();
: : 			String LoanID = l.substring(15, 25).trim();
: : 			String DelqM = l.substring(30).trim();
: : 		
: : 			{
: :      outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
: : 			}
: : 			 }
: :      }
: :      }
: : 	} catch(Exception z){
: :             System.out.println("Error: " + z.toString());
: : 	    }
: : 	    
: :      finally {
: : 		if (inputStream != null) {
: : 			inputStream.close();
: : 		}
: : 		if (outputStream != null) {
: : 			outputStream.close();
: : 		}
: :     }
: : 	}
: : // @return true if it's a junk row
: : // @return false if it's not
: : 
: : private boolean isjunk(String x){
: : 	for(int i = 0; i < junkRow.length();i++){
: : 	if(x.indexOf(junkRow[i])){
: : 		return true;
: : 		}
: : 		if(x.trim().length() < 1) {
: : 			  return true;
: : 		  }
: : 	} return false;
: : }
: : }
: : 
: :
: :
: : Any help would be appreciated.
: :
: : Thanks
: :
: Change isJunk() to:
:
: 
: private boolean isjunk(String x, String[] junkRow)
: 
:
: and then add the junkRow to the parameters. Example:
:
: 
:   isjunk(someString, junkRow)
: 
:
:
: To make it a class field move the junkRow definition to between the
: main() and the line containing the class definition:
:
: 
: public class FileParse {
: 
:     private static String[] junkRow;
: 
:     public void main(String[] args) throws IOException {
: 
:
: because there is no object instance of FileParse, you need to make
: junkRow static. The word private means that other classes cannot use
: it (see variable scopes for more info).

I tried both ways and when I compiled the program I received the following error:

FileParse.java:92: incompatible types
found : int
required: boolean
if(x.indexOf(junkRow[i])) {
^

I just do not get it. Everytime I fix something anothr issue pops up on me.

Thanks
Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 22 Jul 2007 at 6:34 AM

: I tried both ways and when I compiled the program I received the
: following error:
:
: FileParse.java:92: incompatible types
: found : int
: required: boolean
: if(x.indexOf(junkRow[i])) {
: ^
:
: I just do not get it. Everytime I fix something anothr issue pops up
: on me.
:
: Thanks
:
indexOf() gives the index of the character where the junkRow[] starts. Since this is a number and the compiler cannot know what that number should be, you'll need to compare it with another number to use it in an if-statement. For example:
  if (x.indexOf(junkRow[i]) == 0) {

checks if x starts with junkRow[i].
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 22 Jul 2007 at 9:09 AM
:
: : I tried both ways and when I compiled the program I received the
: : following error:
: :
: : FileParse.java:92: incompatible types
: : found : int
: : required: boolean
: : if(x.indexOf(junkRow[i])) {
: : ^
: :
: : I just do not get it. Everytime I fix something anothr issue pops up
: : on me.
: :
: : Thanks
: :
: indexOf() gives the index of the character where the junkRow[]
: starts. Since this is a number and the compiler cannot know what
: that number should be, you'll need to compare it with another number
: to use it in an if-statement. For example:
:
: 
:   if (x.indexOf(junkRow[i]) == 0) {
: 
:
: checks if x starts with junkRow[i].

Thanks for your help and I appreciate your patience with a newbie like myself. I was able to get the program to finally compile but when I tried to run it with the java command I receive this error:

Exception in thread "main" java.lang.NoSuchMethodError: main

Report
Re: New To Java & Need Help With Program I'm Writing Posted by zibadian on 23 Jul 2007 at 3:42 AM
: :
: : : I tried both ways and when I compiled the program I received the
: : : following error:
: : :
: : : FileParse.java:92: incompatible types
: : : found : int
: : : required: boolean
: : : if(x.indexOf(junkRow[i])) {
: : : ^
: : :
: : : I just do not get it. Everytime I fix something anothr issue pops up
: : : on me.
: : :
: : : Thanks
: : :
: : indexOf() gives the index of the character where the junkRow[]
: : starts. Since this is a number and the compiler cannot know what
: : that number should be, you'll need to compare it with another number
: : to use it in an if-statement. For example:
: :
: : 
: :   if (x.indexOf(junkRow[i]) == 0) {
: : 
: :
: : checks if x starts with junkRow[i].
:
: Thanks for your help and I appreciate your patience with a newbie
: like myself. I was able to get the program to finally compile but
: when I tried to run it with the java command I receive this error:
:
: Exception in thread "main" java.lang.NoSuchMethodError: main
:
:
main() must be defined as a static method, because the JVM cannot instanciate the defining class for you.
Report
Re: New To Java & Need Help With Program I'm Writing Posted by adlb1300 on 23 Jul 2007 at 7:32 PM
: : :
: : : : I tried both ways and when I compiled the program I received the
: : : : following error:
: : : :
: : : : FileParse.java:92: incompatible types
: : : : found : int
: : : : required: boolean
: : : : if(x.indexOf(junkRow[i])) {
: : : : ^
: : : :
: : : : I just do not get it. Everytime I fix something anothr issue pops up
: : : : on me.
: : : :
: : : : Thanks

It finally works. Thanks you have been a ton of help.
: : : :
: : : indexOf() gives the index of the character where the junkRow[]
: : : starts. Since this is a number and the compiler cannot know what
: : : that number should be, you'll need to compare it with another number
: : : to use it in an if-statement. For example:
: : :
: : : 
: : :   if (x.indexOf(junkRow[i]) == 0) {
: : : 
: : :
: : : checks if x starts with junkRow[i].
: :
: : Thanks for your help and I appreciate your patience with a newbie
: : like myself. I was able to get the program to finally compile but
: : when I tried to run it with the java command I receive this error:
: :
: : Exception in thread "main" java.lang.NoSuchMethodError: main
: :
: :
: main() must be defined as a static method, because the JVM cannot
: instanciate the defining class for you.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.