Question: Its a Java lab! Overview Write a program that solves quadratic equations and prints their roots. A quadratic equation has the following form: ax +


Its a Java lab!
Overview Write a program that solves quadratic equations and prints their roots. A quadratic equation has the following form: ax + bx +c=0 where a + 0. There are two solutions to such an equation: r = -b + b2 - 4ac 2a Note the + symbol, which indicates one solution (root) is obtained by adding the two terms in the numerator, and the other is obtained by subtracting the two terms. Write a method named printQuadraticRoots that prints an equation and its two roots, and call the method in "main" with the appropriate parameters. You may assume the equation has two real roots and that a 0. Please name your program QuadraticFormula.java Input Specification Use variables a, b, and c to represent the INTEGER coefficients of the equation. These should be read from the user with a Scanner object. Extensively TEST your program with many other values to verify correctness. Input should be in the form: a ==> b ==> C ==> Make sure there is a space before and after the arrow (==> Output Specification Output the equation along with its two roots. You do NOT need to worry about how many digits follow the decimal point. Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output sample below is for the equation Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output sample below is for the equation x2 2x 4=0 Sample Output a ==> 1 b ==> -2. C ==> -4 For the equation "(1)x^2 + (-2) + (-4) = 0", the roots are X = 3.236068 and X = -1.236068 Note: there are two spaces between the beginning of the line and the x output on the second and fourth lines. There is only one space before the and on the third line. Required Methods Include at LEAST the following methods. You will need to DETERMINE the return types and parameters, and the calling relationship between methods. Only call the discriminant method ONCE so you don't compute the same quantity twice. IMPORTANT: make sure you CAREFULLY read what each method does // Print "For the equation ... the roots are" followed by the two roots, in the format above // // HINT: Look at the required variables to determine the parameters DetermineReturnType printQuadraticRoots (...) // Print a quadratic equation using the following format: (a)x^2 + (b)X + (C) = 0 // DO NOT print any quotation marks or newline characters // HINT: Look at the required variables to determine the parameters IMPORTANT: make sure you CAREFULLY read what each method does // Print "For the equation ... the roots are followed by the two roots, in the format above // HINT: Look at the required variables to determine the parameters DetermineReturnType printQuadraticRoots (...) // Print a quadratic equation using the following format: // (a)x^2 + (b)x + (C) = 0 // DO NOT print any quotation marks or newline characters // HINT: Look at the required variables to determine the parameters DetermineReturnType printEquation (...) // Compute and return the discriminant (6^2 - 4ac) // HINT: Look at the required variables to determine the parameters Look at what the discriminant should evaluate to in order // to derive the return type DetermineReturnType calcdiscriminant (...) Hints You may use methods of the Math class. Use Wolfram Alpha to verify that your program is correct. Ensure your program can handle any equation with real roots. Style Use good programming style: Write comments Choose mnemonic, meaningful variable names (e.g. seconds, minutes) Indent consistently (ctrl + Shift + will format your code) Remember the comment block at the top of your program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
