1. Member
Join Date
Nov 2009
Posts
8
Rep Power
0

Hi guys,
I have an assignment of Quadratic Expression and my professor wants me to have these methods:
get() and set() for three variables

getRootOne() : double
getRootTwo() : double
toString() : String
getNumRealRoots() : int

I know how to do all of them except getNumRealRoots() : int
What is this method for? I need help for the logic..

Thanks..:)

2. Member
Join Date
Nov 2009
Posts
96
Rep Power
0
With that name I suppose that he want you to get the roots of the expresion, but I'm surprised that it should return an integer. Are you sure about that? The formula for getting the roots is very simple, the only thing you have to do is compute the solution of the equation a*x^2+b*x+c=0.

roots = [-b +- sqrt(b^2-4a*c)]/2*a

As you can see, the real roots can be represented as floats, but not always as integers.

3. Sky: It's not supposed to return the real roots but to give the count of them. With quadratic equations, that number can be 2, 1, or 0, and is determined by the results of:

(b * b - 4 * a*c)

If this is 0, then there is 1 real root, if > 0, then 2 real roots, if < 0, then no real roots (all roots in this situation are complex).
Last edited by Fubarable; 11-28-2009 at 05:26 PM.

4. Member
Join Date
Nov 2009
Posts
96
Rep Power
0
Yes, you are right, I just missed the word Num. Well, maybe he can add it as an extra :P

5. Originally Posted by sky
roots = [-b +- sqrt(b^2-4a*c)]/2*a
Never calculate the roots of a quadratic equation like that; it is numerically instable; better read this link for a numerical more stable method.

kind regards,

Jos

6. Member
Join Date
Nov 2009
Posts
96
Rep Power
0
Thanks for the link, I didn't know that.

7. Member
Join Date
Nov 2009
Posts
8
Rep Power
0
So..
This getNumRealRoots() only checks if the result of Math.sqrt(b^2 - 4*a*c)?
It is not returning any value that I can use in the calculation of the getRootOne() and getRootTwo()?
Thanks for the expert's help...:)

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•