Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Quadratic Equation
Posted by Matt Gerrans on October 26, 2001 at 2:15 AM
Uh... So, what's your question? (I did fill in part of the code below)  mfg
> I have an assignment where i have to enter methods into a quadratic class. the folowing methods must be used: > getCoefficient(), computeDiscriminant() (b^24ac), displayTwoRealRoots(), displayOneRoot() (if discriminant=0 theres only one solution. it will compute and display that root with formula x= b/2a > I have to add those methods inside main() below.
> // James > // Program 7 > // Due October 26, 2001 > // This program prompts the user for the coefficients a, b, and c in > // the equation a x^2 + b x + c = 0, and then it figures out the roots > // using the quadratic equation > // > // x = (b +/ sqrt(b^2  4ac)) / 2a> import jpb.*; > public class Quadratic > { > public static void main(String[] args) > { > double a, b, c; > double discriminant; > // Get the coefficients from the user > System.out.println("This program solves the quadratic equation: " > + "a x^2 + b x + c = 0"); > System.out.println("Enter the coefficients"); > a = getCoefficient(); > b = getCoefficient(); > c = getCoefficient(); > discriminant = computeDiscriminant(a, b, c); > if (discriminant > 0) > displayTwoRealRoots (a, b, discriminant); > else if (discriminant == 0) > displayOneRoot(a, b); > else > System.out.println("No real roots"); > } > // methods go here. > }
> I know this is huge, any help is appreciated.> James
Replies:
 ROFL !!! Chin Loong October 26, 2001 at 5:22 AM
(0)
