Question
Write a program that generates random numbers representing the three coefficients a , b , and c of the quadratic equation. The values of a
Write a program that generates random numbers representing the three coefficients a, b, and c of the quadratic equation. The values of a should include numbers 1 through 10, the values of b and c should include numbers -5 through 5. The value of the discriminant will determine if the root of the equation will contain two real roots, one real root, or two complex roots. Print the values of a, b, and c. Print the value of the discriminant.
Print an appropriate message for each case. If two real roots are calculated, print the values appropriately. If only one real root is calculated, print a message that only the one root is produced and print the value.
Your program should not calculate the roots if the coefficients will produce complex roots based on the value of the discriminant. Simply print a message that the roots are complex.
Requirements:
Include the required heading as stated in Creating and Submitting Projects in Eclipse
Use of internal documentation
Use the DecimalFormat class to format the roots. There should always be a digit to the left of the decimal point and at least 1 digit to the right of the decimal point. Print up to three decimal places if the digits are not zero. See sample output below.
Use the pow() method and sqrt() method from the Math class
Use the Random class to assign values to a, b, and c
Sample Output:
The coefficients are:
a = 4 b = 4 c = 1
The discriminant is 0.0
Values produce only one root: -0.5
The coefficients are:
a = 9 b = 1 c = 0
The discriminant is 1.0
The roots are: 0.0 and -0.111
The coefficients are:
a = 2 b = 2 c = 2
The discriminant is -12.0
The roots are complex
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started