1. Engineering
  2. Computer Science
  3. intro to java programming problem 910 algebra quadratic equations the...

Question: intro to java programming problem 910 algebra quadratic equations the...

Question details

Intro to java programming, problem 9.10 Algebra Quadratic Equations, the bold is where I am getting my errors

package javaapplication3;
import java.util.Scanner;


public class JavaApplication3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//Problem 9.10
// UML diagram
/*******************************************************
* QuadraticEquation *
--------------------------------------------------------
* -a: double *
* -b: double *
* -c: double *
* +QuadradticEquation(a: double, b: double, c: double) *
* +getA(): double *
* +getB(): double *
* +getC(): double *
* +getDiscriminant(): double *
* +getRoot1(): double *
* +getRoot2(): double *
*******************************************************/

       Scanner input = new Scanner(System.in);

  
       System.out.print("Enter a, b, c: ");
       double a = input.nextDouble();
       double b = input.nextDouble();
       double c = input.nextDouble();


       QuadraticEquation quadraticEquation = new QuadraticEquation(a, b, c);

  
       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()));
       }
  
  
private double a;
private double b;
private double c;

  
QuadraticEquation(double a, double b, double c) {
       this.a = a;
       this.b = b;
       this.c = c;
}

  
public double getA() {
       return a;
}


public double getB() {
       return b;
}


public double getC() {
       return c;
}

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

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


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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution