I\'ve been trying to made this task for some time now but going nowhere. I have
ID: 3639684 • Letter: I
Question
I've been trying to made this task for some time now but going nowhere. I have seen a lot of examples and tested myself but it's not going very well. Anyway this is the task im telling about.
Task 4:
Design and implement an application that draws the graph of equation ax2+ bx + c
Where the values of a,b and c are set using three sliders.
Do not use a picture, but a circle that you draw up. If you hit the inside the half of the radius of the circle you get extra points. Points every time you manage to hit the circle.
Exit the program after a period of time, circles appear faster and faster.
Explanation / Answer
This is the first part , the class ---------------------------------------------------------- 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(); } } public static void main(String[] args) { QuadraticEquations r1 = new QuadraticEquations(1, 2, 1); System.out.println(r1.getSolutions()); QuadraticEquations r2 = new QuadraticEquations(1, 10, 25); System.out.println(r2.getSolutions()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.