All pastes #904300 Raw Edit

Miscellany

public java v1 · immutable
·published 2008-02-14 21:07 UTC
rendered paste body
public class Roots {static void main (String[] args) {//Generally, I find it better to declare your variables and types before using themdouble a, b, c; // (a,b,c are inputs in the quatratic eqation)double yards; //amount of yardsdouble total; //total for the entire costdouble  equation;  //to set equation in normal form//distance from roots (should always be positive.double distance;//first (adding) and second (subtracting) root of the equationint r1, r2; double disciminant;  //a = Integer.parseInt(args[0]); //assign the first runtime input to ab = Integer.parseInt(args[1]); //assign the second runtime input to bc = Integer.parseInt(args[2]); //assign the third runtime input to c//discriminant assumes that the user inputs three values. this creates real, non imaginary solutionsdiscriminant = (Math.pow(b, 2)) - (4 * a * c);//equation =  (a*(Math.pow(x,2)) - (b*x) + c ); //create the quadriatic equation of form ax^2+ bx + C = 0r1 = ( (-b + discriminant) / (2*a) ); //calculate the first root for the first root solution for the quadriatic r2 = ( (-b - discriminant) / (2*a) ); //calculate the second root//calculate the distance between the roots which should *always* be positivedistance = Math.abs(r1-r2);yards = Double.parseDouble(args[3]); // fourth runtime variable is the price for the fence in dollars/yardtotal = (distance * yards); //calculate the total for the fencereturn system.out.println( "Total cost for" + yards + "yards is $" + total );	}}chagas@morphea:~/Desktop$ javac Roots.javaRoots.java:25: cannot find symbolsymbol  : variable discriminantlocation: class Rootsdiscriminant = (Math.pow(b, 2)) - (4 * a * c);^Roots.java:28: cannot find symbolsymbol  : variable discriminantlocation: class Rootsr1 = ( (-b + discriminant) / (2*a) ); //calculate the first root for the first root solution for the quadriatic             ^Roots.java:28: operator + cannot be applied to double,discriminantr1 = ( (-b + discriminant) / (2*a) ); //calculate the first root for the first root solution for the quadriatic        ^Roots.java:28: operator / cannot be applied to <nulltype>,doubler1 = ( (-b + discriminant) / (2*a) ); //calculate the first root for the first root solution for the quadriatic                           ^Roots.java:29: cannot find symbolsymbol  : variable discriminantlocation: class Rootsr2 = ( (-b - discriminant) / (2*a) ); //calculate the second root             ^Roots.java:29: possible loss of precisionfound   : doublerequired: intr2 = ( (-b - discriminant) / (2*a) ); //calculate the second root                           ^Roots.java:38: cannot return a value from method whose result type is voidreturn system.out.println( "Total cost for" + yards + "yards is $" + total );                         ^7 errorschagas@morphea:~/Desktop$