Quadratic equations The form of a quadratic equation is ax2 + 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 = (-b + 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.  ComplexPair: Encapsulates a pair of complex numbers.  Quadratic: Encapsulates a quadratic equation. – Assume the coefficients are all of type int for this example.  SolveEquation: Contains the main method.  (I give this to you it is shown below)   Along with the usual constructors, accessors and mutators you will need the following additional methods:   In the Complex class a method called isReal 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 the solve SolveEquation class found below.  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. Output should make comments as to which type of roots 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Quadratic equations

The form of a quadratic equation is ax2 + 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 = (-b + 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. 

ComplexPair: Encapsulates a pair of complex numbers. 

Quadratic: Encapsulates a quadratic equation. – Assume the coefficients are all of type int for this example. 

SolveEquation: Contains the main method.  (I give this to you it is shown below)

 

Along with the usual constructors, accessors and mutators you will need the following additional methods:

 

In the Complex class a method called isReal 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 the solve SolveEquation class found below.  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.

Output should make comments as to which type of roots 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.

 

SolveEquation class:

public class SolveEquation

{

  public static void main( String [] args )

  {

    Quadratic q1 = new Quadratic( 0, -2, 6 );

    System.out.printf( "Quadratic equation #1: %s\n", q1 );

    ComplexPair c1 = q1.solveQuadratic( );

    System.out.printf( "%s\n", q1.getComment( ) );

    System.out.printf( "Solutions: %s\n\n", c1 );

 

    Quadratic q2 = new Quadratic( -2, 4, -2 );

    System.out.printf( "Quadratic equation #2: %s\n", q2 );

    ComplexPair c2 = q2.solveQuadratic( );

    System.out.printf( "%s\n", q2.getComment( ) );

    System.out.printf( "Solutions: %s\n\n", c2);

 

    Quadratic q3 = new Quadratic( 1, 4, 3 );

    System.out.printf( "Quadratic equation #3: %s\n", q3);

    ComplexPair c3 = q3.solveQuadratic( );

    System.out.printf( "%s\n", q3.getComment( ) );

    System.out.printf( "Solutions: %s\n\n", c3);

    

    Quadratic q4 = new Quadratic( -1, 2, -5 );

    System.out.printf( "Quadratic equation #4: %s\n", q4);

    ComplexPair c4 = q4.solveQuadratic( );

    System.out.printf( "%s\n", q4.getComment( ) );

    System.out.printf( "Solutions: %s\n\n", c4);

  }

}

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

 

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education