As every algebra student knows, the quadratic formula gives the solutions to qua
ID: 3539416 • Letter: A
Question
As every algebra student knows, the quadratic formula gives the solutions to quadratic equations of the form ax^2+bx+c=0. Not many people are aware that a formula also exists to solve cubic equations of the form x^3+ax^2+bx+c=0. This formula is called Cardano's formula, after the Italian mathematician who allegedly derived it several hundred years ago. The formula says that the solution is given by x=u-p/3u-a/3, where p=b-(a^2)/3, q=c+ (2a^3-9ab)/27, u= 3rd root of
a. Using Java's built in Math.pow and Math.sqrt methods, write a method that takes parameters for the coefficients a,b and c, then returns the solution to the cubic equation.
b. Within the same source code file as your solution for (a), write a main method that allows the user to enter values for a,b and c, then calls your method from (a) and displays the result.
Explanation / Answer
Heres my code:
Class 1:
Class 2:
heres my output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.