|
RHS |
Quadratic Equation 01
This exercise is highly inspired by exercise P6.1 from "Big Java", 2nd ed.
A quadratic equation is an equation of the form: ![]()
To satisfy the equation there can be either no solutions, one solution or two solutions.
Which of the 3 alternatives that apply to a certain quadratic equation is determined by the discriminant, given by the expression : ![]()
If the value of the discriminant is negative there is no value of x that satisfies the equation (no solutions).
If the value of the discriminant is zero there is exactly one value of x that satisfies the equation (one solutions).
If the value of the discriminant is larger than zero there is two values of x that satisfies the equation (two solutions).
The class QuadraticEquation stores information about a quadratic equation (the values of a, b and c).
It also offers some utility methods to give information about the equation and is solutions (if any).
You can download the file here: QuadraticEquation.java
If you simply want to see it - maybe for printing - click here: QuadraticEquation for printing
Exercise 1
As the method noOfSolutions() and the constructors in the class QuadraticEquation is not finished you have to do that!
The comments in the class could be helpful...!!
Tip: Start by creating a project in NetBeans (give it a name of your own choice) - remember to remove the choice of a Main class!.
Download QuadraticEquation.java and save it in the src folder of the project-folder.
Finally open it in NetBeans by selecting "Source Packages", then <default package> in the left frame (Projects tab) and click on the filename.
To test the QuadraticEquation class we'll make an application class, QuadEquationTester.
When run it reads 3 values from the user and creates a QuadraticEquation object based on these values.
It then prints information to the screen about this object using the utility methods from the object.
You can download the file here: QuadEquationTester.java
If you simply want to see it - maybe for printing - click here: QuadEquationTester for printing
Exercise 2
As the method write() is not finished you should do that!
Please note that the output must reflect whether there exists zero, one or two solutions for the quadratic equation!
You should use if-else constructions to make that possible!