PDA

View Full Version : java help!




mastabri
Nov 8, 2002, 02:18 AM
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;

}



evildead
Nov 8, 2002, 03:28 AM
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

robbieduncan
Nov 8, 2002, 09:30 AM
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?

bousozoku
Nov 9, 2002, 11:29 PM
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.

macktheknife
Nov 9, 2002, 11:58 PM
Originally posted by evildead
what is FormattedInput? is that a class you wrote?

Exactly. Where did you put this class?