Question: This program should be written in Java. Programs Quadratic equations. (60 points) The form of a quadratic equation is ax? + bx+c=0. Write a program



This program should be written in Java.
Programs Quadratic equations. (60 points) The form of a quadratic equation is ax? + bx+c=0. Write a program that solves a quadratic equation in all cases, including when both roots are complex numbers. Remember that the solutions are x=(-6 + sqrt(b2 -4ac))/2a and (-b - sqrt(b2-4ac))/2a For this you will need to set up the following classes: Complex: Encapsulates a complex number. (15) ComplexPair: Encapsulates a pair of complex numbers. (15) Quadratic: Encapsulates a quadratic equation. Assume the coefficients are all of type int for this example. (30) SolveEquation: Contains the main method. (Get this class in Programs/Lesson2/Homework tab as file SolveEquation.java) Along with the usual constructors, accessors and mutators you will need the following additional methods: In the Complex class a method called is Real to determine whether a complex object is real or not returning a boolean value. In the ComplexPair class a method bothIdentical that determines if both complex numbers are identical, returning a boolean value. In the Quadratic class a method that solves the quadratic equation and returns a ComplexPair object. Please use my solve SolveEquation class for this assignment. The three parameters in each case are for the a, b and c coefficients respectively. SolveEquation includes the main program. It includes all the testing you need. public class SolveEquation { public static void main( String [] args) { Quadratic q1 = new Quadratic( 0, -2, 6); System.out.printf( "Quadratic equation #1: %s ", q1 ); ComplexPair cl = 21.solveQuadratic(); System.out.printf("%s ", 21.getComment()); System.out.printf( "Solutions: %s ", cl); Quadratic q2 = new Quadratic( -2, 4,-2); System.out.printf( "Quadratic equation #2: %s ", 92); ComplexPair c2 = 72.solveQuadratic(); System.out.printf("%s ", q2.getComment()); System.out.printf( "Solutions: %s ", c2); Quadratic q3 = new Quadratic( 1, 4, 3); System.out.printf("Quadratic equation #3: %s ", 43); ComplexPair c3 = 23.solveQuadratic(); System.out.printf("%s ", q3.getComment()); System.out.printf( "Solutions: %s ", c3); Quadratic 24 = new Quadratic(-1, 2,-5); System.out.printf("Quadratic equation #4: %s ", q4); ComplexPair c4 = 24.solveQuadratic(); System.out.printf("%s ", q4.getComment()); System.out.printf( "Solutions: %s ", c4); } } Output should make comments as to which type ofroots we get (double, real real root, distinct roots, complex roots). All coefficients in output should be to 2 decimal places. See below for the sample output. Sample Output: Quadratic equation #1: - 2x + 6 = 0 Linear equation: one real root Solutions: first: 3.00; second: 3.00 Quadratic equation #2: -2x^2 + 4x - 2 = 0 Double real root Solutions: first: 1.00; second: 1.00 Quadratic equation #3: x^2 + 4x + 3 = 0 Two distinct real roots Solutions: first: -1.00; second: -3.00 Quadratic equation #4: -x^2 + 2x - 5 = 0 Two distinct complex roots Solutions: first: 1.00 - 2.00i; second: 1.00 + 2.00i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
