Design a class named QuadraticEquation for a quadratic equation ax2+bx+x=0. The
ID: 3633276 • Letter: D
Question
Design a class named QuadraticEquation for a quadratic equation ax2+bx+x=0. The class contains:private data fields a, b, and c that represents three coefficients.
a constructor for the arguments for a, b, and c.
three get methods for a, b, and c.
a method named getDiscriminant() that returns the discriminant, which is b2-4ac
the methods named getRoot1() and getRoot2() for returning two roots of the equation, or returning 0 if the discriminant is negative.
Write a test program that prompts the user to enter values for a, b, and c and displays the roots. If no roots for the equation, display "The equation has no roots."
Explanation / Answer
public class QuadraticEquation { private int a,b,c; public QuadraticEquation(int x,int y,int z) { a=x; b=y; c=z; } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public int getDiscriminant() { return b*b-4*a*c; } public double getRoot1() { if(getDiscriminant()Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.