• Post Reply Bookmark Topic Watch Topic
  • New Topic

N00b Question: Quadratic Equation Code  RSS feed

 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been doing Java for about two weeks. I'm having a lot of trouble understanding the code for the quadratic equation. Can someone walk me through it please?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It'd be best if you walk through it line by line, telling us what you think it does, and what about each line you do not understand. I'm willing to bet that this exercise helps in and of itself.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a quadratic equation (Ax^2 + Bx + C = 0), A cannot be 0. If A=0, it is a linear equation.

See if it helps.

Chan.
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. This assign the class for the code.
3. Not sure what all of this specifically means yet. My best guess is that this let me do inputs.
4. This is for "bx" in the equation. I don't know what parseDouble does, but I know args[0] is for my first input.
5. This is for "c" in the equation. args[1] is for my 2nd input.
7. I have no clue. What's with the 4.0? Why 4.0 instead of 4?
8. Math.sqrt take the square root. That's all I got.
10-11 I have no clue. I don't understand why we're doing what we're doing.
13. Writes the value for root1 to the Console.
14. Writes the value for root2 to the Console.

 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if you'd want to go through this ---> http://www.teacherschoice.com.au/maths_library/algebra/alg_6.htm
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I just did some reading into this. I understand the math now. Still not sure on the code though.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here are some hints to help you along...
Sam Pauken wrote:1. This assign the class for the code.

The correct word is declares. All code must be within a class, so you always need to create at least one. Most large applications can have hundreds if not thousands of classes.
3. Not sure what all of this specifically means yet. My best guess is that this let me do inputs.

Each class can have any number of methods. The main method is the one that the program will start executing (for most program types).
4. This is for "bx" in the equation. I don't know what parseDouble does, but I know args[0] is for my first input.

And your inputs are always strings. You can't do math on strings, so they need to be converted to a numeric type; in this case doubles.
7. I have no clue. What's with the 4.0? Why 4.0 instead of 4?

Most languages have a handful of different numeric types depending upon the nature of the numbers being represented. For the quadratic equation, integers won't do. 4 is an integer literal. 4.0 is a floating point literal.

I'll let you take it from here...
 
Sam Pauken
Ranch Hand
Posts: 84
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks for your help (and for making me do some of the work on my own).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Pauken wrote:Got it! Thanks for your help (and for making me do some of the work on my own).

You're welcome! And kudos for appreciating that sometimes all you need is nudge in the right direction to figure things out on your own. Not everybody does.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!