n this lab, you will construct a class called QuadraticSolver that will compute the real roots of a quadratic function (�(�) = ��! + �� + �). The class will implement the following methods. • A default constructor that initializes a legitimate quadratic function. • An overloaded constructor that takes the values of a, b, and c in the function �(�) = ��! + �� + �. This method throws a QuadraticException in the case where the input does not define a quadratic function. • A method that computes the discriminant (�! − 4��). • Boolean methods determining whether the solutions of the quadratic equation ��! + �� + � = 0 have real or non-real solutions. • Two methods, one for each real root of the equation ��! + �� + � = 0. Each method will throw a NonRealException when the root is a non-real value. • A toString method that (reasonably) prints the quadratic function. The classes QuadraticException and NonRealException have been provided. Implement a main method in a separate class to test your implementation. Sample input/output is given below: Run 1 Give me a co-efficient a: 0 Give me a co-efficient b: 1 Give me a co-efficient c: 1 Caught a QuadraticException:: Given input does not define a quadratic equation. Run 2 Give me a co-efficient a: 2 Give me a co-efficient b: 0 Give me a co-efficient c: 0 The equation: (2x^2) and has real solutions. Root 1: 0.0 Root 2: 0.0 Run 3 Give me a co-efficient a: 2 Give me a co-efficient b: 8 Give me a co-efficient c: 2 The equation: (2x^2) + (8x) + (2) and has real solutions. Root 1: -0.2679491924311228 Root 2: -3.732050807568877 Run 4 Give me a co-efficient a: -3 Give me a co-efficient b: 2 Give me a co-efficient c: -2 Caught a NonRealException: The roots of the equation are non-real
In this lab, you will construct a class called QuadraticSolver that will compute the real roots of a
quadratic function (�(�) = ��! + �� + �).
The class will implement the following methods.
• A default constructor that initializes a legitimate quadratic function.
• An overloaded constructor that takes the values of a, b, and c in the function �(�) = ��! +
�� + �. This method throws a QuadraticException in the case where the input does not
define a quadratic function.
• A method that computes the discriminant (�! − 4��).
• Boolean methods determining whether the solutions of the quadratic equation ��! + �� + � =
0 have real or non-real solutions.
• Two methods, one for each real root of the equation ��! + �� + � = 0. Each method will throw
a NonRealException when the root is a non-real value.
• A toString method that (reasonably) prints the quadratic function.
The classes QuadraticException and NonRealException have been provided. Implement
a main method in a separate class to test your implementation. Sample input/output is given below:
Run 1
Give me a co-efficient a: 0
Give me a co-efficient b: 1
Give me a co-efficient c: 1
Caught a QuadraticException:: Given input does not define a quadratic equation.
Run 2
Give me a co-efficient a: 2
Give me a co-efficient b: 0
Give me a co-efficient c: 0
The equation: (2x^2)
and has real solutions.
Root 1: 0.0
Root 2: 0.0
Run 3
Give me a co-efficient a: 2
Give me a co-efficient b: 8
Give me a co-efficient c: 2
The equation: (2x^2) + (8x) + (2)
and has real solutions.
Root 1: -0.2679491924311228
Root 2: -3.732050807568877
Run 4
Give me a co-efficient a: -3
Give me a co-efficient b: 2
Give me a co-efficient c: -2
Caught a NonRealException: The roots of the equation are non-real
Trending now
This is a popular solution!
Step by step
Solved in 3 steps