Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview Write a program that solves quadratic equations and prints their roots.

ID: 3593972 • Letter: O

Question

Overview Write a program that solves quadratic equations and prints their roots. A quadratic equation has the following form where a o. There are two solutions to such an equation 2a Note the symbol, which indicates one solution (root) is obtained by adding the two terms in the numerator, and the other is cblained by subtracting the two terms Write a method named printQuadraticRoots that prints an equation and its two roots and call the method in "main" with the apprpriateparameters. You may assume the equation has two real roots and that a0. Please name your program Quadraticformula.java Input Specification Use variables ab, and cto represent the INTEGER coefficients of the equation. These should be reed from the user with a scannar object. Extensively TEST your program with many other values to verify correctness Input should be in the form Make sure there is a space before and after the arrow) Output Specification Output the equation along with its two roots. You do NOT need to worry about how many digits follow the decimal point Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output sample below is for the equation

Explanation / Answer

QuadraticFormula.java

import java.util.Scanner;

public class QuadraticFormula {

public static void main(String[] args) {

int a, b, c;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

// Getting the input entered by the user
System.out.print("Enter a :");
a = sc.nextInt();

System.out.print("Enter b :");
b = sc.nextInt();

System.out.print("Enter c :");
c = sc.nextInt();

// printEquation(a,b,c);
double discriminant = calDiscriminant(a, b, c);

// Based on the discriminant display the corresponding message
if (discriminant == 0) {
System.out.print("For the equation ");
printEquation(a, b, c);
System.out.print(", the root is ");
printQuadraticRoots(discriminant, a, b);
} else if (discriminant < 0) {
System.out.print("For the equation ");
printEquation(a, b, c);
System.out.print(", has no real solutions. ");
} else {
System.out.print("For the equation ");
printEquation(a, b, c);
System.out.print(", the roots are ");
printQuadraticRoots(discriminant, a, b);
}

}

//This method will display the root of the Quadratic equation
private static void printQuadraticRoots(double discriminant, int a, int b) {
if (discriminant == 0) {
System.out.printf("x = %.6f ", ((-b) + Math.sqrt(discriminant)) / (2 * a));
} else if (discriminant > 0) {
System.out.printf("x = %.6f ", ((-b) + Math.sqrt(discriminant)) / (2 * a));
System.out.println("and");
System.out.printf("x = %.6f ", ((-b) - Math.sqrt(discriminant)) / (2 * a));
}

}

//This method will calculate and return the discriminant of the equation
private static double calDiscriminant(int a, int b, int c) {

return Math.pow(b, 2.0) - 4 * a * c;
}

//This method will display the quadratic equation
private static void printEquation(int a, int b, int c) {
System.out.print("(" + a + ")x^2+(" + b + ")x+(" + c + ")=0");

}

}

__________________

Output:

Enter a :1
Enter b :-2
Enter c :-4
For the equation (1)x^2+(-2)x+(-4)=0, the roots are
x = 3.236068
and
x = -1.236068


_____________Could you rate me well.Plz .Thank You