Question: Programming Language: Java import java.io.PrintStream; import java.util.Scanner; public class Lab { /** * discriminant(int, int, int) -> double * * Computes the discriminant b^2 -

Programming Language: Java

Programming Language: Java import java.io.PrintStream; import java.util.Scanner; public class Lab { /**

import java.io.PrintStream; import java.util.Scanner; public class Lab { /** * discriminant(int, int, int) -> double * * Computes the discriminant b^2 - 4ac * @param a the first (int) coefficient of the polynomial ax^2+bx+c * @param b the second (int) coefficient of the polynomial ax^2+bx+c * @param c the third (int) coefficient of the polynomial ax^2+bx+c * @return the (double) discriminant b^2 - 4ac * * IMPLEMENT THE METHOD AFTER THE FOLLOWING LINE */ /** * calcRoot1(int, int, int) -> double * * Computes the first root of a polynomial ax^2+bx+c * @param a the first (int) coefficient of the polynomial ax^2+bx+c * @param b the second (int) coefficient of the polynomial ax^2+bx+c * @param c the third (int) coefficient of the polynomial ax^2+bx+c * @return the (double) root * * IMPLEMENT THE METHOD AFTER THE FOLLOWING LINE */ /** * calcRoot2(int, int, int) -> double * * Computes the second root of a polynomial ax^2+bx+c * @param a the first (int) coefficient of the polynomial ax^2+bx+c * @param b the second (int) coefficient of the polynomial ax^2+bx+c * @param c the third (int) coefficient of the polynomial ax^2+bx+c * @return the (double) root * * IMPLEMENT THE METHOD AFTER THE FOLLOWING LINE */ /** * CPS150_Lab14 : int, int, int ; double * * program is given the coefficients of the polynomial ax^2+bx+c * program calculates and outputs the roots of the polynomial * * NOTE: YOU ARE NOT ALLOWED TO MODIFY THIS main CODE IN ANY WAY */ public static void main(String[] args) { int a, b, c; double root1, root2; Scanner input = new Scanner(System.in); PrintStream output = System.out; output.println("This program calculates the roots of a polynomial"); output.println("ax^2+bx+c, once its gets the coefficients"); output.println("of the polynomial a, b and c "); // get the polynomial's coefficients output.print("Enter the polynomial coefficients (integers) separated by spaces: "); a = input.nextInt(); b = input.nextInt(); c = input.nextInt(); // calculate the roots of the polynomial root1 = calcRoot1(a, b, c); root2 = calcRoot2(a, b, c); // output the roots of the polynomial output.printf(" The polynomial %dx^2 + %dx + %d has the roots %.1f and %.1f ", a, b, c, root1, root2); } // end main method } // end class Lab

This program, once completed, will calculate the roots of a polynomial ax2 + bx + c, using the quadratic equation -b+vb2-4ac 2a 1. Implement the method discriminant to calculate the double discriminant b2 - 4ac, with parameters for the coefficients a, b and cof the polynomial ax2 + bx + c X= 2. Implement the method calcRooti to calculate the double first root x= -b+vb-4 ac, with parameters for the coefficients a, b and cof the polynomial ax + bx + c 2a 3. Implement the method calcRoot2 to calculate the double second root x= -b-vb-4ac, with parameters for the coefficients a, b and cof the polynomial ax + bx + c 2a Once completed, your program should work as follows (user input in color): This program calculates the roots of a polynomial ax^2+bx+c, once its gets the coefficients of the polynomial a, b and c Enter the polynomial coefficients (integers) separated by spaces: 34-2 The polynomial 3x^2 + 4x + -2 has the roots 0.4 and -1.7

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!