The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001

Advertisement

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 Hiran on October 27, 2001 at 10:23 PM

> I have an assignment where i have to enter methods into a quadratic class. the folowing methods must be used:
> getCoefficient(), computeDiscriminant() (b^2-4ac), 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.

> // YOUR NAME HERE
> // 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

What exactly are you stuck on? If you want someone to write those methods for you, I doubt you'll find someone who is willing to help. If, on the other hand, you've attempted to write those methods and you're stuck, just post what you have written (or attempted) and what exactly you're stuck on.
Hiran





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us