Question: JAVA Please check the code I wrote. Then please revise it. Exercise 3.8 asked you to write a method called quadratic that solves quadratic equations

 JAVA Please check the code I wrote. Then please revise it.

JAVA Please check the code I wrote. Then please revise it.

Exercise 3.8 asked you to write a method called quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form a x2 +bx+c = 0. The formula for solving a quadratic equation is: X= b+Vb2 - 4ac 2a Here are some example equations and their roots: equation x2 - 7x + 12 x2 + 3x + 2 call quadratic(1, -7, 12); quadratic(1, 3, 2); output First root = 4.0 First root = -1.0 Second root - 3.0 Second root = -2.0 But for some values of a, b, and c, the formula does not find any valid roots. Under what conditions would this formula fail? Modify the quadratic method so that it will reject invalid values of a, b, or c by throwing an IllegalArgumentException. (You may want to go back and complete the exercise in the previous chapter first.) Type your solution here: 1 public static void quadratic(int a, int b, int c) throws IllegalArgumentException{ float fr (- 6+ (b*b-4*a*c)^(1/2))/(2*a); 3 float sc = - b - (b*b-4*a*c)^(1/2)/(2*a); System.out.println("First root = " + fr); System.out.println("Second root = + SC); 7 8 9 4 5 10)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!