Results 1 to 4 of 4
Thread: Function evaluation.
- 09-09-2012, 04:10 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
Function evaluation.
Help please. There is a class that reads the numbers in the text file "in.txt" and assigns them to the coefficients of a, b, c, d. Next, you need to implement a class that computes the function: y = (int) (a * Math.pow (x, 2) + b * x + c * Math.pow (x, -2) + d). The result must be displayed on the screen and in the text file "out.tht." In organizing the I / O to be used try-catch mechanism to catch exceptions of type IOException. Also need to write a variant in which the main program waives the exception handling with throws.
Example of a class that reads data from a text file.
content "in.txt":Java Code:package test; import java.io.*; class Function { public static void main(String[] args) { FileReader reader = null; try { reader = new FileReader( "C:/in.txt" ); StreamTokenizer in = new StreamTokenizer( reader ); in.parseNumbers(); while (in.nextToken() != StreamTokenizer.TT_EOF) { double a = in.nval; in.nextToken(); double b = in.nval; in.nextToken(); double c = in.nval; in.nextToken(); double d = in.nval; in.nextToken(); double begin = in.nval; in.nextToken(); double end = in.nval; in.nextToken(); double step = in.nval; System.out.println( a + " " + b + " " + c + " " + d + " | " + begin + " " + end + " | " + step); } } catch(Exception e) { e.printStackTrace(); } finally { try { if ( reader != null ) { reader.close(); } } catch(Exception e) { e.printStackTrace(); } } } }
1 0.2 3.4 -1 -10 10 1
-1 3.2 3.4 -1 -10 10 1
1 0.2 3.4 -1 -10 10 1
- 09-09-2012, 04:30 PM #2
Re: Function evaluation.
I don't see what you need help with? :O
I have a feeling that you need to read through these: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes) .
- 09-09-2012, 04:46 PM #3
Re: Function evaluation.
About your topic title: Java doesn't have 'functions' -- they are called methods.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-09-2012, 04:57 PM #4
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
JSTL re evaluation
By ngreddyit in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 07-18-2012, 10:57 PM -
Help needed on evaluation function
By Shashir Bharadwaj in forum Advanced JavaReplies: 4Last Post: 01-18-2012, 08:33 PM -
Critical evaluation
By Noelf21 in forum New To JavaReplies: 3Last Post: 12-11-2009, 12:47 AM -
Creating the evaluation function for Minimax
By matzahboy in forum New To JavaReplies: 7Last Post: 11-05-2009, 03:29 PM -
Postfix Evaluation using a Stack, Help?
By dalangley in forum New To JavaReplies: 2Last Post: 02-16-2009, 10:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks