Question: In class, we wrote a program that solves quadratic equations of the form ax? + b +c= 0. Not many people are aware that a

In class, we wrote a program that solves quadratic equations of the form ax? + b +c= 0. Not many people are aware that a formula also exists to solve cubic equations of the form 2 + pr+q=0 It can be shown that any cubic equation in the general form ar + bx2 + x + d = 0 can be reduced to the form of equation (1), but we won't worry about how to do that here. Equation (1) is solvable using Cardano's formula, named after the Italian mathematician who allegedly derived it during the 1500s. The formula states that the solution is: For now, let's worry only about the real values of the quantities in (2). This means the formula will give you only one of the three roots to (1). Within your Lab2HW folder, write a program named CubicSolver.java that allows the user to enter values (potentially including decimals) for the coefficients p and q from (1). Your program should then compute and display the value of the solution according to (2). Note that although using Math. pou with an exponent of 1/3 works for computing cube roots of positive numbers, Math pow gives a result of NaN when computing the cube root of a negative number. Use Math.cbrt(x) instead: you can replace with whatever you're trying to find the cube root of. Here's an example of what your completed program might look like when you run it. Underlined parts indicate what you type in as the program is running. What is the value of p? 1 What is the value of q? 30 The solution x is -2.9999999999999742. Note that the solution given by your program may not be exact, due to the slight roundoff error that's possible when working with double values. This is totally fine
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
