Results 1 to 4 of 4
  1. #1
    Bkmz8888 is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default 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.
    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();
    
                }
    }
        }
    
        }
    content "in.txt":
    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

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default 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) .

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Function evaluation.

    About your topic title: Java doesn't have 'functions' -- they are called methods.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Bkmz8888 is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default Re: Function evaluation.

    I'm just learning. Java studying the third week. This job practical work that I need to pass soon. If there had been more time, I think he could and do.

Similar Threads

  1. JSTL re evaluation
    By ngreddyit in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-18-2012, 10:57 PM
  2. Help needed on evaluation function
    By Shashir Bharadwaj in forum Advanced Java
    Replies: 4
    Last Post: 01-18-2012, 08:33 PM
  3. Critical evaluation
    By Noelf21 in forum New To Java
    Replies: 3
    Last Post: 12-11-2009, 12:47 AM
  4. Creating the evaluation function for Minimax
    By matzahboy in forum New To Java
    Replies: 7
    Last Post: 11-05-2009, 03:29 PM
  5. Postfix Evaluation using a Stack, Help?
    By dalangley in forum New To Java
    Replies: 2
    Last Post: 02-16-2009, 10:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •