-5

This is the error that I receive:

Multiple markers at this line - Syntax error on token "double", { expected
- Syntax error, insert "interface Identifier" to complete InterfaceHeader
- Syntax error on token "double", @ expected
- Syntax error, insert ")" to complete SingleMemberAnnotation
- Syntax error on token "double", invalid (
- Syntax error, insert "}" to complete MemberValueArrayInitializer

This is my code:

            package CoreMath;


            public double evaluateRoot(double lower, double higher);
            //lower and higher are the initial estimates//
            {
                double fa; //fa and fb are the initial ‘guess’ values.//
                double fb;
                double fc; //fc is the function evaluation , fx//
                double midvalue=0;
                double precvalue=0; {
                    fa=computeFunction(lower); //ComputeFunction is implemented by the caller
                    fb=computeFunction(higher);
                    //Check to see if we have the root within the range bounds//
                    if (fa*fb>0)
                    { //If fa∗fb>0 then both are either positive or negative and don’t bracket zero.//

                        midvalue=0;//Terminate program//
                    }
                    else
                        do
                        {
                            precvalue=midvalue;//preceding value for testing relative precision//

                            midvalue = lower+0.5*(higher-lower);
                            fc=computeFunction(midvalue); //Computes the fx for the mid value//

                            // 1.2. Core Math’s Classes 5

                            if(fa*fc<0)
                            {
                                higher=midvalue;
                            }
                            else
                                if(fa*fc>0)
                                {
                                    lower=midvalue;
                                }

                        } while((abs(fc)>precisionvalue&i<iterations));//loops until desired number of iterations or precision is reached//

                    return midvalue;
                }
            }

Should I be declaring higher and lower elsewhere?

Jammer
  • 1
  • 1
  • 3
    Your method is not inside a class, or your `package` statement is very misplaced. – Arnaud Jun 28 '18 at 13:58
  • 2
    Is it the actual complete code or have you clipped out anything? Where is the class declaration? – Raman Sahasi Jun 28 '18 at 13:58
  • 1
    Remove the semicolon behind `public double evaluateRoot(double lower, double higher);` And please paste the entire class. If this IS the entire code, you should start a few steps earlier on `Class definition`. – Akaino Jun 28 '18 at 14:00
  • I strongly recommend you tu use an IDE to write your code. Syntax errors are often beginners errors (no problem to that), and it's the case here. But it could be easily avoided by using an IDE to learn to code. For example an IDE would have tell you that your code is outside a class, or that there's a problem with a semicolon at the end of your method declaration, etc... – vincrichaud Jun 28 '18 at 14:07

1 Answers1

0

you have a termination after your method declaration

public double evaluateRoot(double lower, double higher);

change it to this one

public double evaluateRoot(double lower, double higher)

solution

public class A {

    // lower and higher are the initial estimates//
    public static double evaluateRoot(double lower, double higher) {
        double fa; // fa and fb are the initial ‘guess’ values.//
        double fb;
        double fc; // fc is the function evaluation , fx//
        double midvalue = 0;
        double precvalue = 0;
        {
            fa = computeFunction(lower); // ComputeFunction is implemented by the caller
            fb = computeFunction(higher);
            // Check to see if we have the root within the range bounds
            if (fa * fb > 0) { // If fa∗fb>0 then both are either positive or negative and don’t bracket zero.
                midvalue = 0;// Terminate program
            } else {
                do {
                    precvalue = midvalue;// preceding value for testing relative precision

                    midvalue = lower + 0.5 * (higher - lower);
                    fc = computeFunction(midvalue); // Computes the fx for the mid value

                    // 1.2. Core Math’s Classes 5

                    if (fa * fc < 0) {
                        higher = midvalue;
                    } else if (fa * fc > 0) {
                        lower = midvalue;
                    }

                }
                while ((abs(fc) > precisionvalue & i < iterations));// loops until desired number of iterations or precision is reached
            }

            return midvalue;
        }
    }
}

and call it by A.evaluateRoot(...);

Chirag
  • 555
  • 1
  • 5
  • 20