Results 1 to 7 of 7
Thread: Reading input file into an array
- 10-18-2008, 09:28 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 3
- Rep Power
- 0
- 10-18-2008, 09:56 PM #2
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
What happens when you try?
- 10-18-2008, 09:57 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 3
- Rep Power
- 0
its not working. if we create an abstract constructor it looses the values after one iteration so i created it in main class but i can't pass it through to abstract class. i thought it might be to do with the string args in the main class?
- 10-18-2008, 10:01 PM #4
You'lll have to describe it a bit more than that.its not working
Posting the code would be useful for anyone wanting to help.
- 10-18-2008, 10:15 PM #5
Member
- Join Date
- Oct 2008
- Posts
- 3
- Rep Power
- 0
this is the main class
package zeroopt.tester;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import zeroopt.functions.*;
import zeroopt.io.InputFile;
import zeroopt.io.OutputFile;
public class ZeroOptTest
{
public static void main( String[] args )
{
String inputFileName;
String outputFileName;
if ( args.length == 0 )
{
inputFileName = "C:\\Numerical_Analytics\\deirdre.txt";
outputFileName = "swnum_1.out";
}
else if ( args.length == 1 )
{
inputFileName = args[0];
outputFileName = "swnum_1.out";
}
else
{
inputFileName = args[0];
outputFileName = args[1];
}
double xTolerence;
String inputs[] = new String[4];
String inputfilename = args[0];
System.out.println("our filename is:"+ inputfilename);
//FileReader fr;
// BufferedReader br;
int counter = 0;
int maxIts;
int i = 0;
double xTolerance;
String filename = "C:\\Numerical_Analytics\\deirdre.txt";
FileReader fr = null;
BufferedReader br;
{
// String filename = "C:\\Numerical_Analytics\\deirdre.txt";
try {
fr = new FileReader (filename);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
br = new BufferedReader( fr );
String line;
try {
while ( (line = br.readLine()) != null )
{
StringTokenizer st = new StringTokenizer( line );
while ( st.hasMoreTokens() )
{
//maxits = ( st.countTokens() );
//maxits = Integer.parseInt(st.hasMoreTokens()) ;
//inputs [i] = Integer.parseInt(st.nextToken()) ;
inputs [i] = st.nextToken() ;
System.out.println( "deirdre inputs"+ inputs[i] );
i++;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
maxIts = Integer.parseInt(inputs[0]);
xTolerance = Double.valueOf(inputs[1].trim()).doubleValue();
try
{
xTolerance = Double.valueOf(inputs[1].trim()).doubleValue();
//System.out.println( "xTolerance "+ xTolerance );
}
catch (NumberFormatException nfe)
{
System.out.println( "NumberFormatException: "
+nfe.getMessage());
}
System.out.println( "maxIts deirdre "+ maxIts );
System.out.println( "xTolerance deirdre"+ xTolerance );
InputFile inFile = new InputFile( inputFileName );
OutputFile outFile = new OutputFile( outputFileName );
ZeroOpt_f g = new ZeroOpt_f( inFile, outFile);
ZeroOpt_f0 h = new ZeroOpt_f0( inFile, outFile);
System.out.println( "Bisect f is " + g.zeroBisect() );
System.out.println( "Bisect f0 is " + h.zeroBisect() );
System.out.println( "Secant f is " + g.zero2Secant() );
System.out.println( "Secant f0 is " + h.zero2Secant() );
outFile.closeWriter( );
inFile.closeReader( );
} // end of method main()
}
}
THIS IS ONE OF THE ABSTRACT METHODS IN OUR ABSTRACT CLASSES
public
double zeroBisect()
{
double x = 0;
System.
out.println("maxits is " + maxIts);
for (int i = 1; i < maxIts; i++)
{
x=
a+(b-a)/2.0;
if (f(x) ==0.0)
{
return x;
}
else
{
if ((f(a)<0.0 && f(x) > 0.0 )|| (f(a)> 0.0 && f(x) < 0.0))
{
b = x;
}
else
{
a = x;
x =
a+(b-a)/2.0;
}
if (Math.abs(a-b) < xTolerance){
return x;
}
}
}
return x;
}
/*end method zeroBisect*/
- 10-18-2008, 10:52 PM #6
Just another cross poster
New To Java - reading input file into an array
db
- 10-18-2008, 11:51 PM #7
Similar Threads
-
[SOLVED] Reading a text file into an Array
By DonCash in forum New To JavaReplies: 13Last Post: 01-25-2011, 12:51 AM -
Making arrays by reading user input
By apfroggy0408 in forum New To JavaReplies: 23Last Post: 04-30-2008, 01:23 AM -
Reading/Writing a File using byte array
By Java Tip in forum Java TipReplies: 0Last Post: 01-16-2008, 10:41 AM -
input placed in array
By smilejava in forum New To JavaReplies: 5Last Post: 11-12-2007, 07:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks