All pastes #904288 Raw Edit

Miscellany

public java v1 · immutable
·published 2008-02-14 20:59 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 );	}}