Write a program Quadratics.java
that asks a user to enter integer values a
, b
, and c
for a quadratic equation of the form y = ax2 + bx + c. The program then will print out the root(s) of the equation, or indicate that there are no roots.
Include the following static methods in your solution:
getNumRoots(int a, int b, int c)
getLeftRoot(int a, int b, int c)
getRightRoot(int a, int b, int c)
main
function should use a Scanner to get coefficients, then call getNumRoots
to determine how many roots there are. Depending on that result, the main
method will call getLeftRoot
and/or getRightRoot
methods as needed.Sample output (note that some rounding errors may occurs--this is normal):
Trial 1 (2 real roots)
Welcome to the Quadratic Solver!
Enter an a value: 1
Enter a b value: -2
Enter a c value: -15
Your left root: -3.0
Your right root: 5.0
Trial 2 (1 real root)
Welcome to the Quadratic Solver!
Enter an a value: 4
Enter a b value: -12
Enter a c value: 9
Your single root: 1.5
Trial 3 (no real roots)
Welcome to the Quadratic Solver!
Enter an a value: 5
Enter a b value: 0
Enter a c value: 6
Your quadratic has no real roots