Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Design a Java class for quadratic equations. Solution public class QuadraticE

ID: 3640782 • Letter: 7

Question

7. Design a Java class for quadratic equations.

Explanation / Answer

public class QuadraticEquations { private double aConstant; private double bConstant; private double cConstant; public QuadraticEquations(double pA, double pB, double pC) { aConstant = pA; bConstant = pB; cConstant = pC; } public double getA() { return aConstant; } public double getB() { return bConstant; } public double getC() { return cConstant; } public boolean hasSolutions() { if(2 * aConstant != 0) { if(((bConstant*bConstant) - 4 * aConstant * cConstant ) >= 0) { return true; } } return false; } public double getFirstSolution() { double firstSolution = aConstant; if(hasSolutions()) { firstSolution = (-bConstant + Math.sqrt(bConstant * bConstant - 4 * aConstant * cConstant))/(2 * aConstant); } return firstSolution; } public double getSecondSolution() { double firstSolution = aConstant; if(hasSolutions()) { firstSolution = (-bConstant - Math.sqrt(bConstant * bConstant - 4 * aConstant * cConstant))/(2 * aConstant); } return firstSolution; } public String getSolutions() { if(!hasSolutions()) { return "The equation " + aConstant + "x + " + bConstant + "x + " + cConstant + "x Has no solutions"; } else { return "the first solution is x = " + getFirstSolution() + " the second solution is x = " + getSecondSolution(); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote