Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2009, 05:59 PM
Member
 
Join Date: Nov 2009
Posts: 8
Rep Power: 0
c3jcarmy is on a distinguished road
Default Quadratic Expression
Hi guys,
I have an assignment of Quadratic Expression and my professor wants me to have these methods:
get() and set() for three variables

add(QuadraticExpression) : QuadraticExpression
substract(QuadraticExpression) : QuadraticExpression
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..
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-28-2009, 06:16 PM
sky sky is offline
Member
 
Join Date: Nov 2009
Posts: 95
Rep Power: 0
sky is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-28-2009, 06:23 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,499
Rep Power: 8
Fubarable is on a distinguished road
Default
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).
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags

Last edited by Fubarable; 11-28-2009 at 06:26 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-28-2009, 06:27 PM
sky sky is offline
Member
 
Join Date: Nov 2009
Posts: 95
Rep Power: 0
sky is on a distinguished road
Default
Yes, you are right, I just missed the word Num. Well, maybe he can add it as an extra :P
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-28-2009, 07:03 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,268
Rep Power: 3
JosAH is on a distinguished road
Default
Originally Posted by sky View Post
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-28-2009, 07:05 PM
sky sky is offline
Member
 
Join Date: Nov 2009
Posts: 95
Rep Power: 0
sky is on a distinguished road
Default
Thanks for the link, I didn't know that.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-28-2009, 07:10 PM
Member
 
Join Date: Nov 2009
Posts: 8
Rep Power: 0
c3jcarmy is on a distinguished road
Default
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...
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-28-2009, 07:16 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,268
Rep Power: 3
JosAH is on a distinguished road
Default
Read the link I supplied in my previous reply.

kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression ras_pari Advanced Java 27 10-07-2009 01:25 PM
program for a quadratic formula bbtgirl New To Java 9 01-30-2009 07:06 PM
Quadratic Equation jpnym15 New To Java 4 11-12-2008 04:29 AM
Quadratic GUI ryn21 New To Java 1 10-30-2008 06:58 AM
Help with quadratic equation in java paul New To Java 1 07-25-2007 09:23 PM


All times are GMT +2. The time now is 01:39 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org