java help!

Discussion in 'Community' started by mastabri, Nov 7, 2002.

  1. mastabri macrumors newbie

    Joined:
    Jul 24, 2002
    #1
    can you tell me what's wrong? it always goes to the error statement

    package program3;

    /**
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    */

    public class Main {
    public static void main(String[] args) {
    FormattedInput keyboard = new FormattedInput();


    int a,b,c,d;
    double x = 0;


    System.out.println("Enter the integer coefficients:");

    a = keyboard.intRead();
    b = keyboard.intRead();
    c = keyboard.intRead();
    d = keyboard.intRead();

    /* Check for non-cubic or trival answer */


    if( check_input(a,b,c,d) == false )
    // If it is a non cubic or has trival answer, quit the program.
    System.exit(0);
    /*
    double y;
    y=cubic(a,b,c,d,x);

    double z;
    z=cubic_slope(b,c,d,x);
    */
    int count=1;
    while(count<=1000){
    x= x-(cubic(a,b,c,d,x)/cubic_slope(b,c,d,x));

    if(verify_root(a,b,c,d,x)==true)
    System.out.println(a+ " +" + b + " *x+" + c + " *x^2+" + d + "*x^3 has root" + x);
    else
    count++;
    }

    System.out.println(a+ " +" + b + " *x+" + c + " *x^2+" + d + " *x^3 does not converge");

    }

    public static double cubic(int a, int b, int c, int d,double x){

    double cubic;
    cubic= a + b*x + c*(x*x) + d*(x*x*x);
    return cubic;



    }


    public static double cubic_slope(int b, int c, int d,double x){

    double cubic_slope;
    cubic_slope= b + 2*c*x + 3*d*(x*x);
    return cubic_slope;

    }

    public static boolean check_input(int a, int b, int c, int d){

    if (a==0){
    System.out.println(a+ " +" + b + " *x+" + c + " *x^2+" + d + " *x^3 has a trivial solution");
    return false;
    }

    if (d==0){
    System.out.println(a+ " +" + b + " *x+" + c + " *x^2+" + d + " *x^3 is not a cubic");
    return false;
    }

    return true;


    }

    public static boolean verify_root(int a, int b, int c, int d,double x){

    boolean verify_root;

    if((a + b*x + c*(x*x) + d*(x*x*x))==0){
    verify_root=true;
    return true;
    }

    return false;

    }
     
  2. evildead macrumors 65816

    evildead

    Joined:
    Jun 18, 2001
    Location:
    WestCost, USA
    #2
    what is

    what is FormattedInput? is that a class you wrote?

    are you using Apple project builder to compile? try using the debugger...

    What kind of errors are you getting?


    is this for a begging programing class? did your professor give you some utillity classes to use? most of the time they give you some simple input classes to make things simple at first
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    Need more data! What is the exact error outputted. Is it from the compiler, or when you run it. Is that the exact file or do you #include anything?
     
  4. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #4
    Without any more information, error message, error location, it's difficult to tell that there's a problem.

    I would guess that FormattedInput needs to be imported or defined in some other way before you can use it there.
     
  5. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #5
    Re: what is

    Exactly. Where did you put this class?
     

Share This Page