Question: Intro to java problem 9.10 the Quadratic Equation, the bold is where i am getting errors and dont know how to fix them import java.util.Scanner;

Intro to java problem 9.10 the Quadratic Equation, the bold is where i am getting errors and dont know how to fix them

import java.util.Scanner;

/** *

*/ public class QuadraticEquation {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //Problem 9.10 Quadratic Equation /** Data fields */ // represent three coeficients private double a; private double b; private double c;

/** Constructor for the arguments for a, b, and c */ QuadraticEquation(double a, double b, double c) { this.a = a; this.b = b; this.c = c; }

public double getA() { return a; }

/** Returns b */ public double getB() { return b; }

/** Returns c */ public double getC() { return c; }

/** Returns the discriminant */ public double getDiscriminant() { return Math.pow(b, 2) - 4 * a * c; }

/** Returns root1 */ public double getRoot1() { return getDiscriminant() < 0 ? 0 : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); }

/** Returns root2 */ public double getRoot2() { return getDiscriminant() < 0 ? 0 : ((-b) - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a); /** Main method */ // Create a Scanner object Scanner input = new Scanner(System.in);

// Prompt the user to enter values for a, b, and c System.out.print("Enter a, b, c: "); double a = input.nextDouble(); double b = input.nextDouble(); double c = input.nextDouble();

// Create a QuadraticEquation object QuadraticEquation quadraticEquation = new QuadraticEquation(a, b, c);

// Compute the real roots of the quadriatic equation if any. System.out.print("The equation has "); if (quadraticEquation.getDiscriminant() < 0) System.out.println("no real roots"); else if (quadraticEquation.getDiscriminant() > 0) { System.out.println("two roots " + quadraticEquation.getRoot1() + " and " + quadraticEquation.getRoot2()); } else { System.out.println("one root " + (quadraticEquation.getRoot1() > 0 ? quadraticEquation.getRoot1() : quadraticEquation.getRoot2())); } } }

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!